简体   繁体   中英

gmap c# point lat long to screen position/location

I'm working with GMap in c#. When I click on the map I whant to get the location on the screen from where I'm clicking. I have a map controller that is called myMap. When I click on the map an event is triggered called myMap_Click(object sender, MouseEventArgs e). If I place an object, in my case a custom form, on the location eX, eY it wont be placed where I click on the screen.

My goal is to desplay a form where I click on the map. I dont care if it follows coordinate if I pan the map or zoom. For now I just want a custom form on the position I click.

How can I get the screen location when I click on the map contoll?

Regards!

It's actually pretty simple!

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();
    }
}        

Obviously replace "Form customForm" parts with your equivalents.

Well you can use this also

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;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM