将坐标放在具有Subgurim Maps的DragEnd事件的文本框上的问题

时间:2011-09-16 09:48:30

标签: asp.net google-maps textbox subgurim-maps

我正在尝试使用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;    
}

基本上我正在创建一个可拖动的标记并向其附加一个事件,该事件由完成赋值的最后一个方法处理......这种情况不会发生。文本框仍然显示为空。

1 个答案:

答案 0 :(得分: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是输入类型文本