Select to view content in your preferred language

allow geolocation

4027
2
Jump to solution
05-04-2015 12:52 AM
sundussabbah
Deactivated User

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???

0 Kudos
1 Solution

Accepted Solutions
ChrisSmith7
Honored Contributor

Sounds like you will need to enable location services on the mobile device.

Here are instructions for Android:

Enable Location Services - Maps for mobile Help

And iPhone:

how do i enable locations services, after origi... | Apple Support Communities

View solution in original post

2 Replies
ChrisSmith7
Honored Contributor

Sounds like you will need to enable location services on the mobile device.

Here are instructions for Android:

Enable Location Services - Maps for mobile Help

And iPhone:

how do i enable locations services, after origi... | Apple Support Communities

sundussabbah
Deactivated User

thank you very much

I was mean enable it by programming

but I understood that the problem occurs because I run the app on simulator, but when I run it on real device it worked

thanks. 

0 Kudos