I am using ArcGIS Javascript SDK 3.17 to display some points on a map, and when the user selects the point it takes them to Google Maps driving directions. The points are displaying in the correct location but when I click the graphic it sends some weird coordinates to Google Maps such as -8622416.7705,4523370.1646
Here is my code for the click event:
map.on("click", function (evt) {
var lat = evt.mapPoint.x.toString();
var lng = evt.mapPoint.y.toString();
window.location = "comgooglemaps://?daddr=" + lat + "," + lng + "&directionsmode=driving";
});
Why is this not working?
-
Because the map is in 3857, web Mercator. You'll need to convert them to lat lon.mkennedy– mkennedy2017年09月29日 13:59:36 +00:00Commented Sep 29, 2017 at 13:59
1 Answer 1
Like @mkennedy said in her comment, you need to convert to a GCS, particularly WGS 1984 if you want lat/long. You can accomplish this using the webMercatorUtils:
// need to import 'esri/geometry/webMercatorUtils' and 'esri/SpatialRefeference'
var wgs84 = new SpatialReference({wkid: 4326});
// convert map coordinates to WGS 84
map.on("click", function (evt) {
if (webMercatorUtils.canProject(evt.mapPoint, wgs84){
var wgsPt = webMercatorUtils.project(evt.mapPoint, wgs84);
window.location = "comgooglemaps://?daddr=" + wgsPt.y + "," + wgsPt.x + "&directionsmode=driving";
}
});
Explore related questions
See similar questions with these tags.