getCurrentPosition() is asynchronous, so how do I return a value from a helper?
Template.pos.helpers({
'nearestLocation': function() {
var location = undefined;
if('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
location = Locations.findOne({
geolocation: {
$near: {
$geometry: {
type: 'Point',
coordinates:[153.0415850, -27.4477160]
},
$maxDistance: 500
}
}
});
console.log(location.name);
return location.name;
});
}
}
});
The find works correctly because the console does output the correct result. Am I missing something I should know about the way Meteor works?