1

我正在尝试使用 Subgurim 创建一个可拖动的标记并将最终变量读取到文本框。

我已经完成了所有工作,除了将坐标放在文本框上的部分。

代码隐藏:

protected void Page_Load(object sender, EventArgs e){
    if (SessionManager.User == null) {
        string strscript  = "<script language=javascript>window.top.close();</script>";
        if(!ClientScript.IsStartupScriptRegistered("clientScript")) {
            ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", strscript);
        }
    }
    else {
        if (!Page.IsPostBack) {                
            gmap.Height = 400;
            gmap.Width = 590;
            gmap.enableDragging = true;
            gmap.Language = "pt";
            gmap.BackColor = Color.White;
            gmap.enableDragging = true;
            gmap.enableGoogleBar = true;

            gmap.Language = "pt";
            gmap.BackColor = Color.White;

            GControl nav = new GControl(GControl.preBuilt.LargeMapControl3D);
            GControl maptypes = new GControl(GControl.preBuilt.MenuMapTypeControl, new GControlPosition(GControlPosition.position.Top_Right));
            GControl scale = new GControl(GControl.preBuilt.ScaleControl, new GControlPosition(GControlPosition.position.Bottom_Left));
            GControl overview = new GControl(GControl.preBuilt.GOverviewMapControl, new GControlPosition(GControlPosition.position.Bottom_Right));

            gmap.addControl(nav);
            gmap.addControl(maptypes);
            gmap.addControl(scale);
            gmap.addControl(overview);

            GLatLng pt=null;
            int zoom = 16;

            string lat = Request.QueryString["lat"];
            string lon = Request.QueryString["lon"];

            if (lon == null || lat == null) {
                pt = new GLatLng(Helper.BASE_LAT, Helper.BASE_LON);
                zoom = Helper.BASE_ZOOM;
            }
            else {
                pt = new GLatLng(Convert.ToDouble(lat), Convert.ToDouble(lon));
            }
            gmap.setCenter(pt,zoom);

            GMarkerOptions mOpts = new GMarkerOptions();
            mOpts.draggable = true;

            GMarker marker = new GMarker(pt,mOpts);
            gmap.addGMarker(marker);

            gmap.addListener(new GListener(marker.ID, GListener.Event.dragend,
                string.Format(@"
                   function(overlay, point)
                   {{
                      var ev = new serverEvent('myDragEnd', {0});
                      ev.addArg({0}.getZoom());
                      ev.addArg(this.getPoint());
                      ev.send();
                   }}
                   ", gmap.GMap_Id)
                )
            );
        }
    }
}

protected string gmap_ServerEvent(object s, GAjaxServerEventOtherArgs e) {    
    switch (e.eventName) {
        case "myDragEnd":
            string zoomLevel = e.eventArgs[0];
            GLatLng point = GAjaxServerEventArgs.latlngFromString(e.eventArgs[1]);
            txtLat.Text = "Hello";//point.lat.ToString();
            txtLon.Text = "There";//point.lng.ToString();
        break;
    }
    return string.Empty;    
}

基本上我正在创建一个可拖动的标记并将一个事件附加到它,这是由完成分配的最后一个方法处理的......这不会发生。文本框仍然显示为空。

4

1 回答 1

0

添加标记时

google.maps.event.addListener(marker, 'dragend', markerDrag);

然后在标题中

function markerDrag(evt)
                 {
                    document.getElementById('mlat_').value = this.getPosition().lat();
                    document.getElementById('mlng_').value = this.getPosition().lng();

                 }

其中 mlat_ 和 mlng 是输入类型文本

于 2014-06-24T13:54:29.597 回答