GMap标记放置在错误的位置 [英] GMap marker is placed in wrong position

查看:111
本文介绍了GMap标记放置在错误的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用winforms和GMap.NET来学习如何使用它.

Im using winforms and GMap.NET in order to learn how to use it.

我在Gmap控制器上以及当用户 点击地图上的某个地方,我会得到x y坐标, 将其转换为纬度和经度,然后绘制标记 在地图上. 但是标记未放置在真正的鼠标光标位置, 看起来该标记具有默认位置,仅此而已. 我试图将鼠标移到另一个地方,并且当我单击标记时 也是在错误的位置创建的(与第一个标记相同)

I have a mouse click action on the Gmap controller and when the user clicks on some place on the map i'm getting the x y coordinates, converting them to latitude and longtitude and then draw the marker on the map. But the marker is not placed in the real mouse cursor location, it looks like the marker has a default place and that's it. I tried to move the mouse to another place and when I clicked the marker was also created at wrong place (it was the same as the first marker)

我尝试在获取坐标之前使用gmap.Overlays.clear() 并放置标记,但这没有帮助.

I tried to use gmap.Overlays.clear() before getting the coordinates and place the marker but this wasn't helpful.

 private void gmap_MouseClick(object sender, MouseEventArgs e)
 {

      if (e.Button == System.Windows.Forms.MouseButtons.Left)
      {
          double lat = gmap.FromLocalToLatLng(e.X, e.Y).Lat;
          double lng = gmap.FromLocalToLatLng(e.X, e.Y).Lng;

          GMapOverlay markerOverlay = new GMapOverlay("markers");

          GMarkerGoogle marker = new GMarkerGoogle(new  
                               GMap.NET.PointLatLng(lat, lng), 
                               GMarkerGoogleType.green_pushpin);

          markerOverlay.Markers.Add(marker);
          gmap.Overlays.Add(markerOverlay);
      }
}

推荐答案

首先添加叠加层,然后添加标记.无需执行其他操作.

Add the overlay first, then add the marker. No need to do extra operations.

gmap.Overlays.Add(markerOverlay);
markerOverlay.Markers.Add(marker);

通过切换语句,您将获得正确的定位.我猜,关于默认头寸的猜测有些正确.叠加层尚未钩"到地图上,因此事先已在其中定位了一个标记.这就是为什么该职位通常最初会处于关闭状态.

By switching around the statements you'll achieve the right positioning. The guess about a default position is somewhat true, I guess. The overlay has not been "hooked" to the map and gets a marker positioned in it beforehand. That's why the position is usually off initially.

这篇关于GMap标记放置在错误的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆