【问题标题】:gmap c# point lat long to screen position/locationgmap c#点经纬度到屏幕位置/位置
【发布时间】:2013-07-16 07:40:51
【问题描述】:
我正在使用 C# 中的 GMap。当我单击地图时,我想从我单击的位置获取屏幕上的位置。
我有一个名为 myMap 的地图控制器。当我点击地图时,会触发一个名为 myMap_Click(object sender, MouseEventArgs e) 的事件。如果我在 e.X, e.Y 位置放置一个对象(在我的情况下是自定义表单),它将不会放置在我点击屏幕的位置。
我的目标是显示我在地图上单击的表单。如果我平移地图或缩放,我不在乎它是否遵循坐标。现在我只想在我点击的位置有一个自定义表单。
点击地图控制时如何获取屏幕位置?
问候!
【问题讨论】:
标签:
c#
google-maps
location
latitude-longitude
screen-positioning
【解决方案1】:
其实很简单!
private void myMap_Click(object sender, MouseEventArgs e)
{
using (Form customForm = new Form())
{
customForm.StartPosition = FormStartPosition.Manual;
customForm.DesktopLocation = MainMap.PointToScreen(e.Location);
customForm.ShowDialog();
}
}
显然将“Form customForm”部分替换为您的等价物。
【解决方案2】:
你也可以用这个
gMapControl1.MouseClick += new MouseEventHandler(map_mouseCLick);
private void map_mouseCLick(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left) {
var point = gMapControl1.FromLocalToLatLng(e.X, e.Y);
double lat = point.Lat;
double lon = point.Lng;
//this the the values of latitude in double when you click
double newPointLat = lat;
//this the the values of longitude in double when you click
double newPointLong = lon;
}
}