convert x y to lat long

10502
6
Jump to solution
05-29-2013 07:12 AM
RichardDeVita
New Contributor
I have a map with multiple layers.  I got this from an example.

streetMap =    new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer", {id:"streetMap"});

  map.addLayer(streetMap);

The layers display and I can switch between layers.  all is fine.

I can draw on the map.  I want to save to points of the polygon.  However the points I get from the geometry object are x y not
latitude and longitude.



dojo.connect(tb, "onDrawEnd", addGraphic);


function addGraphic(geometry) {

  var pts = geometry.rings; 

pts is a array of x and y coords.

How do i get the graphics object to return Latitude and longitude ?  Or how do I convert x y to latitude and logitude ?

Thank you
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
You can use esri.geometry.xyToLngLat, which translates Web Mercator coordinates to lat/long.

View solution in original post

0 Kudos
6 Replies
TimDine
Occasional Contributor II
You could project the points using a geometry service.

http://developers.arcgis.com/en/javascript/jssamples/util_project.html
0 Kudos
KenBuja
MVP Esteemed Contributor
You can use esri.geometry.xyToLngLat, which translates Web Mercator coordinates to lat/long.
0 Kudos
RichardDeVita
New Contributor
Thank You.

esri.geometry.xyToLngLat  is working.

the app is  using esri.layers.ArcGISTiledMapServiceLayer  to add several layers.

streetMap, imagery, topoolgies and some others

In some variations I also set the extent. 

map.setExtent(new esri.geometry.Extent(-144.1358, 7.9814859, -52.76454, 68.8952, new esri.SpatialReference({wkid: 4326})));

Does the wkid  have any effect on xyToLngLat ?  

Also set layers does not have a wkid parameter.  what does it use ?

Again, thank you
0 Kudos
KenBuja
MVP Esteemed Contributor
Don't forget to click the check mark and promote the post that best answered your original question.

The conversion will only work for a geographic coordinate system, and I believe (and someone please correct me if I'm wrong) only with 4326.
0 Kudos
TimDine
Occasional Contributor II
Correct, that function will only do web mercator to WGS84 Decimal Degrees.

Geometry service sample from ESRI would be used to project between other coordinate systems.
0 Kudos
JeffJacobson
Occasional Contributor III
A good alternative to using a Geometry service to do projections is to use proj4js and do the conversions on the client.
0 Kudos