function projectToWebMercator(evt) { map.graphics.clear(); var point = evt.mapPoint; var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND); var graphic = new esri.Graphic(point, symbol); var outSR = new esri.SpatialReference({ wkid: 102113}); map.graphics.add(graphic); alert("Before method"); gsvc.project([ graphic ], outSR, function(features) { alert("inside method"); pt = features[0].geometry; graphic.setInfoTemplate(new esri.InfoTemplate("Coordinates", "<p> X: " + pt.x + "<br/> Y: " + pt.y + "</p>" + "<input type='button' value='Convert back to LatLong' onclick='projectToLatLong();' />" + "<div id='latlong'></div>")); map.infoWindow .setTitle(graphic.getTitle()) .setContent(graphic.getContent()) .show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint)); }); }gsvc = new esri.tasks.GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");Solved! Go to Solution.
gsvc = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");function zoomToLocation(location) {
// use this if basemap is WGS84 --- var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
//otherwise, use this stuff below - basically we make a new point with the geolocated coordinates and reproject it, but to do so, you make the point
//first and specify it's originating spatial reference so then you can reproject it to your own wkid
var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude, new esri.SpatialReference({wkid: 4236})); //don't forget to specify the originating wkid (in this case from the GPS/Geolocation)
var outSR = new esri.SpatialReference({ wkid: 27700});
gsvc.project([ pt ], outSR, function(projectedPoints) {
pt = projectedPoints[0];
map.centerAndZoom(pt, 12);
//add graphic at current location - if graphic exists just move it
if (!graphic) {
addGraphic(pt);
}
else { //move the graphic if it already exists
graphic.setGeometry(pt);
}
map.centerAt(pt);
})
}gsvc = new esri.tasks.GeometryService("local server");gsvc = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");