In this lab, you will add basic geolocation functionality to an Esri Leaflet application.
Open the starter map HTML and copy the contents to a new jsbin.com.
Add a function to get the current geolocation position from the Geolocation API:
because of security rules introduced in Chrome 50 (on 4/20/2016), it is mandatory to configure https in order to take advantage of HTML5 location when you move your website into production.
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
alert("Geolocation is not supported by this browser.");
}
}
getCurrentPosition()
: function showPosition(position) {
map.setView([position.coords.latitude, position.coords.longitude], 14);
}
getLocation();
Your app should run like this one:
Geolocation.watchPosition()
.