node.js - Possible to evaluate an if block to more than just true or false in meteor -
i have helper function meteor template , ideally have 3 different outcomes appear. 1 correct outcome inccorect outcome , 1 if user denies access browser access location, see below:
template.header.created = 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); if( lat >= 51.521606 && lat <= 51.522606 && lon >= -0.078805 && lon <= -0.077705 ) { session.set("locationcheck",true); } else { session.set("locationcheck",false); } } function error_callback(p){ session.set("locationcheck",false); } }
as can see depends on whether callback successful or not.
if trying pass more boolean logic function, should use string or number return. can acheived by:
template.header.created = 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); if( lat >= 51.521606 && lat <= 51.522606 && lon >= -0.078805 && lon <= -0.077705 ) { session.set("locationcheck",0); } else { session.set("locationcheck",1); } } function error_callback(p){ session.set("locationcheck",2); } }
and work there.
Comments
Post a Comment