Meteor (React) - Geolocation.latLng()/Geolocation.currentLocation() returning null


#1

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

#2

Check Geolocation.error() to see if you’re getting any errors.
I think Chrome doesn’t allow geolocation without HTTPS for example.


#3
   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.


#4

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)

#5

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.