Returning value of one function in javascript to next javascript function in the same page -
Returning value of one function in javascript to next javascript function in the same page -
i not able homecoming value of pos
function loc
next function initialize. function pos gives me current latitude , longitude , want utilize these values in next javascript function initialize. value of pos on running initialize function gives undefined.
function loc() { navigator.geolocation.getcurrentposition(function(position) { pos = new google.maps.latlng(position.coords.latitude,position.coords.longitude); homecoming pos; }); } function initialize() { var x = loc(); alert(x); centrallocation = new google.maps.latlng(40.6940741,-73.9869325); var request = { location: centrallocation, types: ['clothing_store'], rankby: google.maps.places.rankby.distance }; google.maps.event.adddomlistener(window, 'load',initialize);
how utilize value of pos in initialize function in var centrallocation
i.e want pass value of pos in var centrallocation
parameter.
it undefined
because getcurrentposition
asynchronous. should place logic within callback of getcurrentposition
function initialize() { navigator.geolocation.getcurrentposition(function(position) { pos = new google.maps.latlng(position.coords.latitude,position.coords.longitude); centrallocation = new google.maps.latlng(40.6940741,-73.9869325); var request = { location: centrallocation, types: ['clothing_store'], rankby: google.maps.places.rankby.distance }; }); }
javascript
Comments
Post a Comment