Just starting out? Need help? Post your questions and find answers here.
-
Dirk Geppert
- Posts: 285
- Joined: Fri Sep 22, 2017 7:02 am
Post
by Dirk Geppert »
Does not work on Safari/iPhone: the Browser dont ask me, to allow the geolocation..
You can try it here:
http://h2717740.stratoserver.net/app/geo/index1.html
or with an Map:
http://h2717740.stratoserver.net/app/geo/index.html
Code: Select all
Enumeration
#Window
#Button
#Link
EndEnumeration
Procedure TimerEvent()
Static x.d, y.d
Protected flags
If x <> GeolocationLatitude()
x = GeolocationLatitude()
flags = #True
EndIf
If y <> GeolocationLongitude()
y = GeolocationLongitude()
flags = #True
EndIf
If flags = #True
Debug "GeolocationTime: " + GeolocationTime()
Debug "GeolocationLatitude: " + GeolocationLatitude()
Debug "GeolocationLongitude: " + GeolocationLongitude()
Debug "----"
EndIf
EndProcedure
Procedure Start_Locating()
Static flags = #False
If flags = #False
flags = #True
Debug "StartGeolocation()"
StartGeolocation()
SetGadgetText(#Button, "Stop")
AddWindowTimer(0, 0, 1000)
BindEvent(#PB_Event_Timer, @TimerEvent(), 0, 0)
Else
flags = #False
StopGeolocation()
Debug "StoppGeolocation()"
SetGadgetText(#Button, "Start again")
RemoveWindowTimer(0, 0)
UnbindEvent(#PB_Event_Timer, @TimerEvent())
EndIf
EndProcedure
Procedure Main()
OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 500, 500, "GeoLocation", #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
ButtonGadget (#Button, 0, WindowHeight(#Window) - 20, WindowWidth(#Window)/2, 20, "Start Locating..")
BindGadgetEvent(#Button, @Start_Locating(), #PB_EventType_LeftClick)
TextGadget (#Link, WindowWidth(#Window)/2, WindowHeight(#Window) - 20, WindowWidth(#Window)/2, 20, "")
SetGadgetText (#Link, ~"<a href = \"#\" button onclick=\"f_start_locating()\">Try it from here It</a>")
EndProcedure
Main()
-
Fred
- Site Admin
- Posts: 1510
- Joined: Mon Feb 24, 2014 10:51 am
Post
by Fred »
Safari only allows geolocation if the site is secured (https://). I will add this to the doc.
-
Dirk Geppert
- Posts: 285
- Joined: Fri Sep 22, 2017 7:02 am
Post
by Dirk Geppert »
I could have used today the geolocation function again. Currently it doesn't work with iPhone and Safari even on an https page.
-
Dirk Geppert
- Posts: 285
- Joined: Fri Sep 22, 2017 7:02 am
Post
by Dirk Geppert »
Workaround with javascript:
Code: Select all
; !! works only with https !!
Structure _coords
latitude.d ; :51.07772692107438
longitude.d ; :13.717396259307861
accuracy.i ; 10
altitude.d ; null
altitudeAccuracy.i ;
heading.i
speed.i
timestamp.i
EndStructure
Global G_Coords._coords
Procedure GetLocation (object)
Protected JsonID, txt.s
! v_txt = JSON.stringify(v_object);
JsonID = ParseJSON(#PB_Any, txt)
If JsonID
jObj = GetJSONMember(JSONValue(JsonID), "coords")
If jObj
jObj = GetJSONElement(jObj, 0)
If jObj
ExtractJSONStructure(jObj, @G_Coords, _coords)
EndIf
EndIf
jObj = GetJSONMember(JSONValue(JsonID), "timestamp")
G_Coords\timestamp = GetJSONInteger(jObj)
FreeJSON(JsonID)
EndIf
Debug G_Coords\latitude
Debug G_Coords\longitude
EndProcedure
Procedure GetGeoLocation()
! if ( navigator.permissions && navigator.permissions.query) {
! //try permissions APIs first
! navigator.permissions.query({ name: 'geolocation' }).then(function(result) {
! // Will return ['granted', 'prompt', 'denied']
! const permission = result.state;
! if ( permission === 'granted' || permission === 'prompt' ) {
! navigator.geolocation.getCurrentPosition(f_getlocation);
! }
! });
! } else if (navigator.geolocation) {
! //then Navigation APIs
! navigator.geolocation.getCurrentPosition(f_getlocation);
! }
EndProcedure
GetGeoLocation()