javascript - Geolocation Error Detection -


i'm using geolocation i'm having trouble recognizing errors able offer alternative.

my html looks this:

<button onclick="getlocation()">get location now</button> <div id="google_canvas"></div> <p id = 'error'></p> 

my script looks this:

function getlocation(){   if(navigator.geolocation)    {     var map;     var mapoptions =      {       zoom: 13,       maptypeid: google.maps.maptypeid.roadmap     }                map = new google.maps.map(document.getelementbyid('google_canvas'), mapoptions);     navigator.geolocation.getcurrentposition(function(position)      {       var geolocate = new google.maps.latlng(position.coords.latitude, position.coords.longitude),latitude=document.getelementbyid("latitude"),longitude=document.getelementbyid("longitude");       var infowindow = new google.maps.infowindow(       {         map: map,         position: geolocate,         content:         ' * output content within map * '       });        map.setcenter(geolocate);       latitude.value = position.coords.latitude;       longitude.value = position.coords.longitude;     });            }     else    {     document.getelementbyid('error').innerhtml = 'no geolocation support';   }   }; google.maps.event.addlistener(map, 'idle', function() { }); 

my version of ie9 not support geolocation (i've tried test site own script), gives me no error or warning, plus if not allow location in firefox or chrome, don't error or alert either.

can help? if cannot run, can offer alternative don't think need through error codes much, need able detect failure can offer alternative, error portion in script not run, regardless.

my question is, why won't else run?

else  { document.getelementbyid('error').innerhtml = 'no geolocation support'; } 

thanks

for error message appear if browser not support geolocation, enable disable geolocation on browser supports need take next address bar there should small icon can use disable/enable geolocation.

in order detect previous decision weather enabled/disabled geolocation can use solution suggested in article :

is there way of detecting whether user has given permission use navigator.geolocation?

for ie9 working fine, thing should click allow blocked cnotent @ bottom of web page.

enter image description here


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -