Select to view content in your preferred language

showing lat/long on mouse move

573
4
01-28-2011 08:11 AM
SangamLama
Emerging Contributor
Hi,

I implemented an eventhandler that shows map co-cordinates when mouse hovers on the map. I followed this tutorial http://resources.esri.com/help/9.3/arcgisserver/apis/silverlight/samples/start.htm#MouseCoords

But I get huge numbers (example: X=1313829.334, Y=2801189.49) for coordinates instead of the +/- 180 range. I looked at the web service where the map data is coming out of, and noticed that the big numbers seem to be representing the map extent?(XMin: 1315433.26465964
YMin: 280294.468654908
XMax: 1318786.62214751
YMax: 283455.239814947)


So what's the difference? How can I display the proper coordinates?

Thanks,
0 Kudos
4 Replies
by Anonymous User
Not applicable
The coordinates displayed are the units defined by the maps spatial reference.
So for example if the maps spatial reference is web mercator the units are meters. You can reproject from webmercator to geographic by using the ESRI.ArcGIS.Client.Bing.WebMercatorToGeographic method.
0 Kudos
SangamLama
Emerging Contributor
The coordinates displayed are the units defined by the maps spatial reference.
So for example if the maps spatial reference is web mercator the units are meters. You can reproject from webmercator to geographic by using the ESRI.ArcGIS.Client.Bing.WebMercatorToGeographic method.


thanks for the response.

I tried using that method, but it returns "Invalid spatial reference." error.

ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = MyMap.ScreenToMap(screenPoint);
                MapPoint point = ESRI.ArcGIS.Client.Bing.Transform.WebMercatorToGeographic(mapPoint); // error thrown here
                MapCoordsTextBlock.Text = string.Format("Coordinates: X = {0}, Y = {1}", Math.Round(point.Extent.XMin, 4), Math.Round(point.Extent.YMin, 4));

Two things: First, is that the correct approach? Second, can I still achieve the geographic coordinates without having to rely on the Bing assembly?
0 Kudos
dotMorten_esri
Esri Notable Contributor
1. Don't use the bing one (its obsolete). Use the ESRI.ArcGIS.Client.Projection.WebMercator class instead (that way you don't need a reference to the Bing assembly either).
2. If you get invalid spatial reference, then your input points are not WebMercator, and you will need to use the GeometryService task to perform the projection serverside (note: Don't try this on mousemove, which would swamp your server in requests).
0 Kudos
SangamLama
Emerging Contributor
1. Don't use the bing one (its obsolete). Use the ESRI.ArcGIS.Client.Projection.WebMercator class instead (that way you don't need a reference to the Bing assembly either).
2. If you get invalid spatial reference, then your input points are not WebMercator, and you will need to use the GeometryService task to perform the projection serverside (note: Don't try this on mousemove, which would swamp your server in requests).


thanks Morten! 🙂
0 Kudos