Hello,
I'm developing app on a mobile and I want to obtain the current location of the device
I used this code:
require(["esri/map", "esri/geometry/webMercatorUtils", "esri/geometry/Point"],function(Map, webMercatorUtils, Point){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(zoomToLocation, locationError);
navigator.geolocation.watchPosition(showLocation, locationError);
}
function zoomToLocation(location) {
var pt = webMercatorUtils.geographicToWebMercator(new Point(location.coords.longitude, location.coords.latitude));
// map.centerAndZoom(pt, 16);
}
function showLocation(location) {
if (location.coords.accuracy <= 500) {
go.alert('<=500');
} else {
go.alert('>500');
}
}
function locationError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
go.alert("Location not provided");
break;
case error.POSITION_UNAVAILABLE:
go.alert("Current location not available");
break;
case error.TIMEOUT:
go.alert("Timeout");
break;
default:
go.alert("unknown error");
break;
}
}
});
but it returned this error: error.PERMISSION_DENIED
which I think mean that geolocation is not enabled
How can I enable it and solve the problem???