How to determine the coordinates of the point on the map, where they clicked the mouse

1004
2
05-23-2017 10:39 PM
YuriGvozdev
New Contributor II

I need to write code that returns the geographical coordinates of the location on the map where the mouse is clicked v100

0 Kudos
2 Replies
TonyWakim
Esri Contributor

Yuri,

You can try something like this:

myMapView.GeoViewTapped += myView_GeoViewTapped;

...

        private void myView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            Point screenPoint = e.Position;
            MapPoint p1 = myMapView.ScreenToLocation(screenPoint);

            var coordsTxt = p1.X.ToString() + " -- " + p1.Y.ToString();
            coordsTxt += "\n";
            MapPoint p2 = (MapPoint)GeometryEngine.Project(p1, SpatialReferences.Wgs84);
            coordsTxt += p2.X.ToString() + " -- " + p2.Y.ToString();
            MessageBox.Show(coordsTxt);
        }
dotMorten_esri
Esri Notable Contributor

GeoViewInputEventArgs also have a 'Location" property already converted to map coordinates, so you don't need to do the ScreenToLocation call, simplifying the first two lines:

MapPoint p1 = e.Location;