Get geo location position

I could not get a solution for this
code :

Dim lat,lon,tlat,tlon
tlat = lat
tlon = lon

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 .

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.

then how to get my functon worked ?

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