I am trying to load the Google Maps javascript API on the server side of my meteor app. I added two methods to Meteor.methods
that use the google.maps but no matter how I try to load the api, I receive the error Exception while invoking method 'getCoords' ReferenceError: google is not defined
. I understand that I cannot use the <src>
tag to load the api, as I was using when I was prototyping with the API on the client side. I also tried using Iron Router with the waitOn library like so:
Router.map( function () {
this.route('codeEditor',{
waitOn: function(){
return [IRLibLoader.load('https://maps.googleapis.com/maps/api/js?libraries=places,geometry?key=MyKey')]
}
});
});
The relevant methods I have created are:
Meteor.startup(function() {
Meteor.methods({
getCoords: function(startLocation,endLocation,priceFilter) {
var directionsService = new google.maps.DirectionsService();
var path = []
var request = {
origin:startLocation,
destination:endLocation,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
path = result.routes[0].overview_path;
Meteor.call('samplePath',path);
}
});
If you have any insights, I would greatly appreciate them! Thank you!