Im very new to Meteor but so far Im really enjoying coding on the platform. I have come up against a bit of hurdle and cant seem to find the correct way. I want to create a helper function that will check lat and long and check it against some predefined range if it falls in between these it returns true.
I have included the code I currently have:
Template.header.helpers({
locationCheck: function() {
navigator.geolocation.getCurrentPosition(success_callback,error_callback);
function success_callback(p){
// Building Latitude = 51.522206
// Building Longitude = -0.078305
var lat = parseFloat(p.coords.latitude);
var lon = parseFloat(p.coords.longitude);
console.log('Latitude: '+lat);
console.log('Longitiude: '+lon);
if( lat >= 51.521606 && lat <= 51.522606 && lon >= -0.078805 && lon <= -0.077705 ) {
console.log('you are in the area');
return 1;
} else {
console.log('you are not in the area');
return 0;
}
}
function error_callback(p){
return 0;
}
}
});
And in my template I want to use the return value in a handlebars if statement, like so:
{{#if locationCheck}}
{{loginButtons}}
{{else}}
<p>Your are out of the vicinity</p>
{{/if}}
The problem is it is consistently return the else statement result even though in the console it is returning this you are in the area
.
Any help would be awesome.
Thanks in advance.