Author Topic: Javascript location of device problem  (Read 259 times)

Javascript location of device problem
« on: July 25, 2019, 11:58:04 am »
I having trouble getting javascript to find where a webpage is being viewed from.

Strangely, I can run a javascript function that can find out the position, but I don't seem to be able to use it outside the function. Also the javascript function does not seem to complete, and code that follows the function call is run before most of the function.

Anyhow, here is the function on it's own, along with the source:- https://mtrak.co.uk/javalocation.php

The code says that the lat and long are undefined, in code that runs after those should have been found.

Any suggestions appreciated.
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Re: Javascript location of device problem
« Reply #1 on: July 25, 2019, 12:08:40 pm »
It doesn't run after they've been found though. It runs after you've requested that it go and find them. It's asynchronous.
Anything that relies on the values, you need to trigger from the showPosition2 function.
It is what it is. It's not what it's not, so it must be what it is.

Re: Javascript location of device problem
« Reply #2 on: July 25, 2019, 12:12:18 pm »
"showPosition2" will be called at a later time when the location has been determined.

The last two lines of your sample will be run immediately, when the location most definitely won't have been defined.

Basically the code that needs to use your location needs to be called from showPosition2.

Re: Javascript location of device problem
« Reply #3 on: July 25, 2019, 12:23:35 pm »
Thanks for that.

Although it will mean a significant rearrangement of the code, it does seem that I'll put what needs the result within the ShowPostion function.
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...