Can't able to fetch the user location in meteor

64 Views Asked by At

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

meteor add mdg:geolocation    
meteor add jeremy:geocomplete    
meteor aldeed:geocoder    
meteor add jaymc:google-reverse-geocode

The code written at client side is as follows:

  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);

        },

      })

    }

But I am getting false value for GoogleMaps.loaded() function and the following below error when I click a button to fetch the location.

Can't able to read formatted address of undefined.

enter image description here

Results are inconsistent as sometimes I was able to fetch the location other times not.

Please give any suggestions...

0

There are 0 best solutions below