Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
Determine latitude and longitude on map click event
posted

Using the OpenStreet map example, how can I determine the geodetic location of a user click?  It seems that I should be able to use the UnProjectFromMap method to convert from Cartesian coordinates, but I'm unsure how to obtain the Cartesian coordinate of the click in the maps internal coordinate system.  The MapMouseLeftDown event, for example, provides a Point that corresponds to the ViewPort coordinate.

Thanks in advance!

  • 28496
    Verified Answer
    Offline posted

    you can use this code to get the geodetic coordinate of the point that was clicked on:

     private void XamWebMap_MapMouseLeftButtonDown(object sender, MapMouseButtonEventArgs e)
            {
                XamWebMap theMap = (XamWebMap)sender;
                Point mousePosition = e.Position;
                Point mapPosition = theMap.Viewport.RootCanvas.RenderTransform.Inverse.Transform(mousePosition);
                Point geoPosition = theMap.MapProjection.UnprojectFromMap(mapPosition);

    }