Convert coordinates

3003
6
12-14-2011 11:05 AM
RossPearson
New Contributor
Hi there,
i'm kinda new to this and i'm trying to get the "Current Location with temporal renderer" sample for mobiles to work with a custom map. The map i'm using has a different spatial reference. So when the position is displayed, it is way off.

As far as i can tell, the coordinates in the sample are converted from WGS84 (format in the Geolocation API) to Web Mercator. Is there any way to convert them to the spatial reference my map is using?

Here's the sample i used (i just changed the map URL in the code):

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/mobile_geoloca...
0 Kudos
6 Replies
derekswingley1
Frequent Contributor
What's your map's spatial reference? Your best bet is probably to use a geometry service's project method to convert from lat/long to your spatial reference.
0 Kudos
RossPearson
New Contributor
Ok, thanks.

Is there a sample of it being used anywhere?

The spatial reference is WKID: 3006.

Appreciate the help!
0 Kudos
derekswingley1
Frequent Contributor
We have a sample showing how to use the geometry service to project a point: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/util_project.html

For your case, you'll want to specify a different out spatial reference:
function projectPoint() {
  var outSR = new esri.SpatialReference({ wkid: 3006});
  gsvc.project([ pt ], outSR, function(projectedPoints) {
    pt = projectedPoints[0];
    // do something with coordinates
  });
}
0 Kudos
RossPearson
New Contributor
Great, tanks alot!
0 Kudos
RossPearson
New Contributor
Does this make sense?


function zoomToLocation(location) {
        pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude);
        

 var outSR = new esri.SpatialReference({ wkid: 3006});
 gsvc.project([ pt ], outSR, function(projectedPoints) {
 pt = projectedPoints[0];

     map.centerAndZoom(pt, 8);
   });
      }
0 Kudos
derekswingley1
Frequent Contributor
Yes, that looks like it should work.
0 Kudos