10

When trying to use the HTML5 geolocation api on mobile chrome for ios, my app throws a "Permission Denied" error without even prompting to share my location. Has anyone else run into this issue?

PS. This happens locally and on a heroku instance.

Here is the code I am running on document ready

    var displayCloseFoo = function(position) {
        var lat = position.coords.latitude;
        var lon = position.coords.longitude;

    };

    var displayError =  function(error) {
        var errors = {
            1: 'Permission denied',
            2: 'Position unavailable',
            3: 'Request timeout'
        };
        alert("Error: " + errors[error.code]);
    };

    var runGeo =  function(){
        if (navigator.geolocation) {
            var timeoutVal = 10 * 1000 * 1000;
            navigator.geolocation.getCurrentPosition(
                    displayCloseFoo,
                    displayError,
                    { enableHighAccuracy: true, timeout: timeoutVal, maximumAge: 0 }
            );
        }
        else {
            alert("Geolocation is not supported by this browser");
        }
    };
    runGeo();

Thanks

Adam
  • 39,529
  • 15
  • 101
  • 139
chad
  • 228
  • 1
  • 3
  • 8

3 Answers3

5

You have to explicitly allow Mobile Chrome to use Location Services in ios. In ios6 you can achieve this by going to Settings->Privacy->Location Services and toggling Chrome to On.

chad
  • 228
  • 1
  • 3
  • 8
0

Geolocation will not work locally in Chrome... Not sure why it wouldn't work from your Heroku instance

Check out this Fiddle... it seems to work fine here... http://jsfiddle.net/mattnull/YaCRe/

mattnull
  • 322
  • 2
  • 9
  • This does not work for mobile chrome on ios. Just opened the fiddle up on my phone and it gives me the same behavior as my code above. – chad Aug 15 '12 at 14:45
  • weird.. I did the same thing and it worked on my phone... do you have location services turned on? This maybe needs to be enabled – mattnull Aug 15 '12 at 14:48
  • So I noticed that once you deny it once, and then reload.. it will continue to say permission denied... I think this is because it adds an exception into Chrome to deny further access. – mattnull Aug 15 '12 at 15:05
  • interesting, im pretty sure that I never denied it, but i'll try to look into the chrome exceptions – chad Aug 15 '12 at 17:59
0

After installing the chrome.when it gets open,it asks u to share your location if u denied u will not get the location

sarat
  • 1