javascript - Error handling not working with HTML5 geolocation in Chrome -


i have simple map should load centered around user's location long allow html5 geolocation. there's function in place incase don't choose allow see location, reason doesn't work.

here's code:

 var x = document.getelementbyid("msg");     function getlocation() {         if (modernizr.geolocation) {             navigator.geolocation.getcurrentposition(showposition, showerror);         }         else { x.innerhtml = "geolocation not supported browser."; }     }     function showposition(position) {         var mapoptions = {             center: new google.maps.latlng(position.coords.latitude, position.coords.longitude),             zoom: 10,             maptypeid: google.maps.maptypeid.roadmap         };         var map = new google.maps.map(document.getelementbyid("map"), mapoptions);         var acoptions = {             types: ['establishment']         };         var autocomplete = new google.maps.places.autocomplete(document.getelementbyid('autocomplete'), acoptions);         autocomplete.bindto('bounds', map);         var infowindow = new google.maps.infowindow();         var marker = new google.maps.marker({             map: map         });         google.maps.event.addlistener(autocomplete, 'place_changed', function () {             infowindow.close();             var place = autocomplete.getplace();             if (place.geometry.viewport) {                 map.fitbounds(place.geometry.viewport);             } else {                 map.setcenter(place.geometry.location);                 map.setzoom(17);             }             marker.setposition(place.geometry.location);             infowindow.setcontent('<div><strong>' + place.name + '</strong><br />');             infowindow.open(map, marker);             google.maps.event.addlistener(marker, 'click', function (e) {                 infowindow.open(map, marker);             });         });     }      function showerror(error) {         switch (error.code) {             case error.permission_denied:                 x.innerhtml = "user denied request geolocation."                 break;             case error.position_unavailable:                 x.innerhtml = "location information unavailable."                 break;             case error.timeout:                 x.innerhtml = "the request user location timed out."                 break;             default:                 x.innerhtml = "an unknown error occurred."                 break;         }     }     google.maps.event.adddomlistener(window, 'load', getlocation); 

and of course <p> element in body id of msg.

your'e noticing doesn't fire in ff, because see "not now" not should fire error - see here (last response says "stop reopening bug, it's design way"):

https://bugzilla.mozilla.org/show_bug.cgi?id=635175

but

timeout acceptable property of options argument (optional third argument) of navigator.geolocation.getcurrentposition. navigator.geolocation.getcurrentposition(showposition, showerror, {timeout:8000}); way showerror after 8 seconds of "inactivity" - in case of firefox means "not answering explicitly yes or never".

ps - asked , answered : function fail never called if user declines share geolocation in firefox


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -