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.
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;
}
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.