I'm trying to use a geocoder package I found on atmosphere (aldeed:geocoder) which use the node-geocoder package. The meteor package specifies that in order to perform a new geocode, i'm to create a new instance of GeoCoder, and then call the geocode method on it, passing in an address string, like so:
var geo = new GeoCoder();
var result = geo.geocode("location");
If I put the above in a server.js file in the server file of my app and console.log result, I get an object printed to the terminal as expected. The problem I'm running into is when I try to call this using a meteor method, in response to user input from a search box. My template helper has this in it:
Template.layout.events({
'submit form': function(e) {
e.preventDefault();
var search = {
location: $(e.target).find('[name=search]').val()
}
console.log(search.location);
Meteor.call('getGeoCode', search.location, function(result) {
console.log(result)
});
}
});
and the collection's file, forecasts.js has this in it:
Forecasts = new Mongo.Collection('forecasts');
Meteor.methods({
getGeoCode: function(search) {
var geo = new GeoCoder();
result = geo.geocode(search);
return result;
}
});
But when I try it out, I get an error in the console that tells me that GeoCoder is undefined. Specifically:
"Exception while simulating the effect of invoking 'getGeoCode'" ReferenceError: GeoCoder is not defined
So, what's going on here? Why isn't it possible to create a new GeoCoder instance in that method and call it like I'm doing?
Aucun commentaire:
Enregistrer un commentaire