I haven’t touched Meteor in a while and I’m attempting to call the Google Maps api and reverse lookup a city state based on lat/long, and everything works fine when I just console.log, but when I attempt to set a reactiveVar (thus showing location on the html page) I go over my request quota in GMaps api. I attempted to make my call in my template’s onCreated event, but I didn’t get anything returned. I’ve tried random combos of Promises, etc, but think I’m just doing something fundamentally wrong here… any tips?
Template.landing.helpers({
currentLocation(){
const instance = Template.instance();
const latLng = Geolocation.latLng();
instance.locationObj.set(latLng);
if (GoogleMaps.loaded() && instance.locationObj.get()) {
const geo = new google.maps.Geocoder();
geo.geocode({
'latLng': instance.locationObj.get()
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
const location = results[0].address_components;
console.log("location in geocode", location);
const city = location[2].short_name;
const state = location[6].short_name;
const locationString = `${city} , ${state}`;
console.log('locationStringe',locationString);
// instance.locationObj.set(locationString);
}
else {
console.error("Geocode was not successful for the following reason: " + status);
}
})
}
return instance.locationObj.get().lat
}
});