javascript - Using geolocation inside angularjs -


i've found have use think workaround geolocation data browser api. question why can't accessed normal way when can see output data in console log?

for example, in case lat , long output, "mapoutput" never updated:

function get_location() {   navigator.geolocation.getcurrentposition(show_map);   console.log('nav: ', navigator); }  function show_map(position) {   var latitude = position.coords.latitude;   var longitude = position.coords.longitude;    self.mapoutput = "http://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";   console.log("latitude: ", latitude);   console.log("longitude: ", longitude); }  get_location(); 

i thought show_map asynchronous callback, why isn't self.mapoutput updated properly?

angular updates data bindings when $digest run. callbacks set through angular functions, done angular code. if go outside of angular must wrapping body of callback in call $apply.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -