Select to view content in your preferred language

Showing lat/long on mouse move

1131
3
04-21-2011 02:33 AM
SantoshV
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/a...tm#MouseCoords

But I get numbers (example: X=1313829.334, Y=2801189.49) for coordinates instead . 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)

but I want to show the lat/long in degree minutes and seconds

I have seen read a few post but never manged to get it working..
Please to help me in this regards
0 Kudos
3 Replies
GéraldReusser
Emerging Contributor
Hi santoshf2,

Which kind of projection are you using ? If you are using the "standard" projection of ArcGIS Server, the map is in WebMercator format.

If you want to have a projection similar as Google or Bings, you must convert this format into WGS 84.

There is a class on API to help you to make the convertion.

See what I have do on my project :

[PHP]        private WebMercator webMercator = new WebMercator();

        private void OnMapMouseMove(object sender, MouseEventArgs e) {
            if (Map == null) {
                return;
            }
            Point screenPoint = e.GetPosition(Map);
            MapPoint webMercatorMapPoint = Map.ScreenToMap(screenPoint);

            if (webMercatorMapPoint != null) {
                MapPoint wsg86MapPoint = (MapPoint)webMercator.ToGeographic(webMercatorMapPoint);

                Y = wsg86MapPoint.Y; // latitude in decimal
                X = wsg86MapPoint.X; // longitude in decimal
            }
        }[/PHP]

If you wanted to show this result into degree/minute/second, you may easily find the good formula on google.

Regards
Jérôme
0 Kudos
SantoshV
Emerging Contributor
thanx for the code it worked like a charm 🙂

Hi santoshf2,

Which kind of projection are you using ? If you are using the "standard" projection of ArcGIS Server, the map is in WebMercator format.

If you want to have a projection similar as Google or Bings, you must convert this format into WGS 84.

There is a class on API to help you to make the convertion.

See what I have do on my project :

[PHP]        private WebMercator webMercator = new WebMercator();

        private void OnMapMouseMove(object sender, MouseEventArgs e) {
            if (Map == null) {
                return;
            }
            Point screenPoint = e.GetPosition(Map);
            MapPoint webMercatorMapPoint = Map.ScreenToMap(screenPoint);

            if (webMercatorMapPoint != null) {
                MapPoint wsg86MapPoint = (MapPoint)webMercator.ToGeographic(webMercatorMapPoint);

                Y = wsg86MapPoint.Y; // latitude in decimal
                X = wsg86MapPoint.X; // longitude in decimal
            }
        }[/PHP]

If you wanted to show this result into degree/minute/second, you may easily find the good formula on google.

Regards
Jérôme
0 Kudos
ducksunlimited
Deactivated User
Thanks for the codes - helpped me


Hi santoshf2,

Which kind of projection are you using ? If you are using the "standard" projection of ArcGIS Server, the map is in WebMercator format.

If you want to have a projection similar as Google or Bings, you must convert this format into WGS 84.

There is a class on API to help you to make the convertion.

See what I have do on my project :

[PHP]        private WebMercator webMercator = new WebMercator();

        private void OnMapMouseMove(object sender, MouseEventArgs e) {
            if (Map == null) {
                return;
            }
            Point screenPoint = e.GetPosition(Map);
            MapPoint webMercatorMapPoint = Map.ScreenToMap(screenPoint);

            if (webMercatorMapPoint != null) {
                MapPoint wsg86MapPoint = (MapPoint)webMercator.ToGeographic(webMercatorMapPoint);

                Y = wsg86MapPoint.Y; // latitude in decimal
                X = wsg86MapPoint.X; // longitude in decimal
            }
        }[/PHP]

If you wanted to show this result into degree/minute/second, you may easily find the good formula on google.

Regards
Jérôme
0 Kudos