0
    navigator.geolocation.getCurrentPosition(
      function(pos) {
        var fullpos = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
        computePartners(fullpos);
      }
    );

is what I have. It executes computePartners() if the client has allowed access for knowing where he is (getting clients physical position). But if it has not, I would like to make output an alert('Error'), example. How can i do this?

Karem
  • 17,615
  • 72
  • 178
  • 278

1 Answers1

3

I use this code for geolocation:

if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
        // ok           
    }, function(error) {
        if(error.code == 0){
        // unknown error
        } else if(error.code == 1) {
        // permission denied
        } else if(error.code == 2) {
        // position unavailable
        } else if(error.code == 3) {
        // timeout
        }
        console.log(error.message);
    }, {
        enableHighAccuracy: true, 
        maximumAge: 30000,
        timeout: 10000    
    });
} else {
         // browser do not support geolocation
}
hamczu
  • 1,774
  • 12
  • 14
  • Okay the user accepted and brwoser part works fine. But not the user denied, i tried to place a alert() there. Then i access my site, and when it ask I say press "not now", and nothing happens.. – Karem Jan 08 '12 at 23:50
  • That is strange - [documentation](http://developer.mozilla.org/En/Using_geolocation) stated as I have written. Maybe you must set timeout parameter like [someone suggests](http://stackoverflow.com/questions/3397585/navigator-geolocation-getcurrentposition-sometimes-works-sometimes-doesnt) ? Which browser do use use? – hamczu Jan 08 '12 at 23:55