Get geo location position


#1

I could not get a solution for this
code :

Dim lat,lon,tlat,tlon
navigator.geolocation.getCurrentPosition(handler)
tlat = lat
tlon = lon
Calculate(tdate,tlat,tlon)

Function handler(location)
  lon = location.coords.longitude
  lat = location.coords.latitude
End Function

I am not able to get lat lon here . “print lat & lon” inside function handler works . But I want lat and lon for my Calculate function .


#2

navigator.geolocation.getCurrentPosition(handler) happens asynchronously: the call to the function gets made. Execution of your code continues while the function is processing.

The statement

tlat = lat

is executed before the function returns, which is why it is undefined.


#3

then how to get my functon worked ?


#4

Any code which depends on the result of getCurrentPosition has to be in the handler.