NetTalk Central
NetTalk Web Server => Web Server - Ask For Help => Topic started by: Robert Iliuta on March 26, 2019, 02:45:28 AM
-
Hallo!
I need to get the Geolocation (Lat & Lon)
Something like in example: https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation (https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation)
When I push a button I want to insert Lat & Lon. (this will be done from a mobile device)
What is a good and smart way to do this?
Thank you!
Robert
-
nettalk....
-
p_web.SetSessionValue('Latitude',GLO:Latitude)
p_web.SetSessionValue('Longitude',GLO:Longitude)
-
Hallo Richard!
Sorry, but from your post I understand ... nothing :-)
Robert
-
for the JavaScript "onclick" for your button use;
'getLocation();'
this will ask the user to approve the use of the location, then (assuming they say yes) send a number of location parameters to the server. Once that has arrived in the server those parameters are stored in session values for you. The values are;
_Latitude_
_Longitude_
_Altitude_
_Accuracy_
_AltitudeAccuracy_
_Heading_
_Speed_
_LocationUnixTime_
_LocationDate_
_LocationTime_
_LocationError_
not all devices populate all fields.
You can then use these sessions values in your program as you need to.
lat = p_web.GetSessionValue('_latitude_')
Cheers
Bruce
-
Sorry Robert,
My keyboard got itself under my reference stuff when I was looking to reply...
I provide location tracking of employees using my netclock (but aside, I have moved on from this and now store Permitted IP addresses.)
This is what I do in a Routine...
p_web.GetLocation()
GLO:Latitude = CLIP(p_web.GetSessionValue('_Latitude_'))
GLO:Longitude = CLIP(p_web.GetSessionValue('_Longitude_'))
SET(nLog)
nLog:EmployeeID = p_web.GetSessionValue('EmployeeID')
nLog:Identifier = p_web.GetSessionValue('Identifier')
nLog:Name = p_web.GetSessionValue('Employee')
nLog:HourlyRate = p_web.GetSessionValue('HourlyRate')
nLog:Department = p_web.GetSessionValue('Department')
nLog:ZoneNumber = p_web.GetSessionValue('ZoneNumber')
nLog:ParentCompany = p_web.GetSessionValue('ParentCompany')
nLog:CompanyName = nlog:ParentCompany
nLog:DateIn = TODAY()
nLog:ActuallogTimeIn = CLOCK()
nLog:Totaltimeworked = 0
nLog:ElapsedTime = 0
nLog:Mobile = 1
CASE lRetroLogin
OF 0
nLog:TimeIn = CLOCK()
OF 1
nLog:TimeIn = lRetroStartTime
END
nLog:Department = p_web.getsessionvalue('DEP:Name')
nLog:Mobile = 1
nlog:Spy = 0
nLog:Notes = lmemo
p_web._Trace('nLog:Notes on start = '& clip(nLog:Notes))
p_web._Trace('lmemo on start = ' &lmemo)
IF nlog:Notes Not = '' then nlog:Spy = 1 END
SET(TRACK)
TRA:Datein = nLog:DateIn
TRA:Timein = nLog:TimeIn
TRA:Name = nLog:Name
TRA:Department = nLog:Department
TRA:Latitude = GLO:Latitude ! OR TRA:Latitude = p_web.GetSessionValue('Latitude')
TRA:Longitude = GLO:Longitude ! OR TRA:Longitude = p_web.GetSessionValue('Longitude')
Access:TRACK.INSERT()
-
Hallo Richard & Bruce!
@Richard
I didn't know about this method p_web.GetLocation()
Thank you! Now it works.
@Bruce
I did exactly like you write (before) but the results came after 3-5 sec so my record is already added.
Only second time it will populate because is already in session.
With the p_web.GetLocation() works much better. I got the response much faster.
Thank you!
Robert
-
Hi Richard,
This code will fail;
p_web.GetLocation()
GLO:Latitude = CLIP(p_web.GetSessionValue('_Latitude_'))
GLO:Longitude = CLIP(p_web.GetSessionValue('_Longitude_'))
The call to GetLocation simply adds a bit of javascript code to the outgoing packet. The browser will get that script, execute it, and then send the session values to the server.
So examining the content of the session value immediately after the call would just get the _previous_ value in teh session queue.
If you need the location when on a form then I recommend calling p_web.GetLocation when the form _opens_. This gives the device time to reply before the user clicks the Save button. Incidentally you can also prime fields on the form with the location (see the Priming tab for that.)
Remember all of this is very asynchronous.
cheers
Bruce