Can't able to fetch the user location in meteor


#1

I developed a meteor app in which while registering I am fetching the user location at client side,to do so I have added some packages listed below:

meteor add mdg:geolocation

meteor add jeremy:geocomplete

meteor aldeed:geocoder

meteor add jaymc:google-reverse-geocode

But I am getting the following error in console.
new1

But sometimes,I was able to fetch location but sometimes it won’t.

Please give any suggestions…


#2

Please give us some code to work by. By stating that sometimes it works and sometimes it does not, I’m guessing you make a call before everything is loaded, but without code…?


#3
 if (Meteor.isClient) { 

 Meteor.startup(() => {
  GoogleMaps.load({
   v: '3.26',
   key: '',                                   
  libraries: 'geometry,places'
  });
 console.log("is GoogleMaps.loaded",GooglMaps.loaded());
 });

   Template.Registration.onRendered(function () {
      Tracker.autorun(() => {
        if (GoogleMaps.loaded()) {

           $('#txt_address').geocomplete({country: "AU", type: 
           ['()']});

            }      
          });
       var date = new Date();
      $('#div_dob').datetimepicker({ 
        format: 'DD/MM/YYYY',
        maxDate : date,
        ignoreReadonly: true

       });
      date=null;
     });

    Template.Registration.helpers({
      location:function(){
       $('input[name="txt_address"]').val(Session.get('location'));
     }
    });

     Template.Registration.events({
      'click #btn_findlocation':function(event){
         alert('Find Location')
        event.preventDefault();
        function success(position) {
        var crd = position.coords;
        console.log(`Latitude0 : ${crd.latitude}`);
        console.log(`Longitude0: ${crd.longitude}`);
        var lat = crd.latitude;
        var long = crd.longitude;
        reverseGeocode.getLocation(lat, long, function(location)
        {           
   console.log("Address",JSON.stringify(reverseGeocode.getAddrStr()));
         Session.set('location', reverseGeocode.getAddrStr());
          });

          };// end of function success(position)

        function error(err) {
           console.warn('ERROR(' + err.code + '): ' + err.message); 
        };//end of function error(err) 

     // geolocation options
        var options = {
         enableHighAccuracy: true,
         maximumAge: 0
          };// end of  var options

       navigator.geolocation.getCurrentPosition(success, error, 
         options);

        },

      })

    }