0

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?

asked Sep 29, 2017 at 13:54
1
  • Because the map is in 3857, web Mercator. You'll need to convert them to lat lon. Commented Sep 29, 2017 at 13:59

1 Answer 1

3

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";
 }
});
answered Sep 29, 2017 at 14:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.