I'm using the locate function to get the user's location, as follows:
map.locate({watch: true})
.on('locationfound', function(e) {
console.log(location);
userlat = location.coords.latitude;
userlong = location.coords.longitude;
useraccuracy = location.coords.accuracy;
L.marker([userlat, userlong]).addTo(map);
})
.on('locationerror', function(e){
console.log(e);
alert("Location access denied.");
});
The browser requests permission to use my location, and I grant it. However, while locationfound fires, all the values of location are 'undefined'.
Location is enabled on my computer - it works in other situations, such as Google Maps.
If anyone can advise on what the issue might be, I'd be very grateful.