Location is undefined

29 views
Skip to first unread message

James Bridle

unread,
Apr 17, 2014, 8:23:43 AM4/17/14
to leafl...@googlegroups.com
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.

Gregory Manushkin

unread,
May 8, 2014, 6:47:00 AM5/8/14
to leafl...@googlegroups.com
Hi James

this should work
inspect "e" in console


  map.locate({watch: true})
     .on('locationfound', function(e) {
        console.log(e);
        useraccuracy = e.accuracy;
        L.marker(e.latlng).addTo(map);

James Bridle

unread,
May 9, 2014, 11:55:40 AM5/9/14
to leafl...@googlegroups.com
It certainly did. Thanks.
Reply all
Reply to author
Forward
0 new messages