niryariv / tiptipa

Mobile friendly minisite for location nearby Polio vaccination centers in Israel
http://tipa.li/
BSD 3-Clause "New" or "Revised" License
3 stars 5 forks source link

Explicit failure for Geolocation not allowed #16

Open alonisser opened 10 years ago

alonisser commented 10 years ago

judging by the example from the leaflet blog should be quite simple:

ow we have a working fullscreen mobile map! But what if we need to do something after the geolocation completed? Here’s what the locationfound and locationerror events are for. Let’s for example add a marker in the detected location, showing accuracy in a popup, by adding an event listener to locationfound event before the locateAndSetView call:

function onLocationFound(e) { var radius = e.accuracy / 2;

L.marker(e.latlng).addTo(map)
    .bindPopup("You are within " + radius + " meters from this point").openPopup();

L.circle(e.latlng, radius).addTo(map);

}

map.on('locationfound', onLocationFound); Excellent! But it would also be nice to show an error message if the geolocation failed:

function onLocationError(e) { alert(e.message); }

map.on('locationerror', onLocationError);

If you have setView option set to true and the geolocation failed, it will set the view to the whole world.