Search code examples
c#google-mapslocationlatitude-longitudescreen-positioning

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 e.X, e.Y 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!


Solution

  • 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.