javascript - Facing trouble with global variable in JS -


following code track user location,

var curr_loc; //global varible function displaylocation(loc) {     currlat = loc.coords.latitude;     currlon = loc.coords.longitude;     curr_loc = currlat + "," + currlon;     alert(curr_loc); //displaying latitude , longitude values  }  function foo() {     navigator.geolocation.getcurrentposition(displaylocation);     alert(curr_loc); //undefined } foo(); 

how can access location values in foo method.

navigator.geolocation.getcurrentposition(displaylocation) returns before position established, , displaylocation called @ point in future when position available. curr_loc undefined time after navigator.geolocation.getcurrentposition() returns, because displaylocation has not been called yet.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -