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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -