I am using Esri for .NET. I trap screen coordinates by mouse click using ScreenToLocation function. How can I convert this mappoint to SP of 4326?
MapPoint mapPoint = Mapview.ScreenToLocation(screenPoint);
My mappoint is not where I clicked on the map. I get the coordinates as 5423799.44921864,-267641.097678069
Are you using the ArcGIS Runtime for windows store or the runtime for wpf?
Anyway, you are getting a WebMercator point. In order to convert between spatial references you need to use the project method of the GeometryService on wpf or the GeometryEngine on the winstore
Or, if you prefer to do the conversion WebMercator (102100/3857) to WGS84 (4326) synchronously by code, you can do with:
private const double R_MAJOR = 6378137.0;
private const double R_MINOR = 6356752.3142;
public MapPoint PointToWGS84(double x, double y)
{
double originShift = 2 * Math.PI * R_MAJOR / 2.0;
double mx = (x / originShift) * 180.0;
double my = (y / originShift) * 180.0;
my = (180 / Math.PI) * (2 * Math.Atan(Math.Exp(my * Math.PI / 180.0)) - Math.PI / 2.0);
return new MapPoint(mx, my, new SpatialReference(WGS84));
}
To go from WGS84 to WM
public MapPoint PointToWM(double x, double y)
{
double originShift = 2 * Math.PI * R_MAJOR / 2.0;
double mx = x * originShift / 180.0;
double my = Math.Log(Math.Tan((90.0 + y) * Math.PI / 360.0)) / (Math.PI / 180.0);
my = my * originShift / 180.0;
return new MapPoint(mx, my, new SpatialReference(102100));
}
please note that this code works ONLY for WM to/from WGS. For other conversions you must always use the GeometryService