I am using mdg:geolocation atmosphere package for getting current location. I am getting ‘null’ as a result of Geolocation.latLng() and also Geolocation.currentLocation(). It indicates no location. My question is how to deal with it. I am working with Meteor React so no helper is there. So trying to get result in autorun.
handleMapOptions() {
Tracker.autorun(() => {
var latLng = Geolocation.currentLocation();
var latLng1 = Geolocation.latLng();
// Initialize the map once we have the latLng.
console.log(latLng);
console.log(latLng1);
});
if (GoogleMaps.loaded()) {
return {
center : new google.maps.LatLng(37.779161, -122.435228),
zoom : 12,
};
}
}
Check Geolocation.error() to see if you’re getting any errors.
I think Chrome doesn’t allow geolocation without HTTPS for example.
Tracker.autorun(() => {
var latLng = Geolocation.currentLocation();
var latLng1 = Geolocation.latLng();
var error = Geolocation.error() ;
// Initialize the map once we have the latLng.
console.log(latLng); //null
console.log(latLng1); //null
console.log(error); //null
});
I am trying all this on localhost.
Weird. mdg:geolocation just provides minor conveniences though, you don’t really need it, so if you don’t feel like troubleshooting any more, you could just use the core browser feature:
navigator.geolocation.getCurrentPosition(console.log)
or to watch for changes:
navigator.geolocation.watchPosition(console.log)
Geolocation.latLng()/Geolocation.currentLocation() gave me lat long only once, and now null. Don’t know what is going wrong. Well navigator.geolocation.getCurrentPosition() working fine for me.
Thank you.