Android Question Problem with Geolocation

ciginfo

Well-Known Member
Licensed User
Longtime User
Problem with Geolocation
Hello,
My app was working correctly and for a few days it crashes as soon as I call NEW_POSITION. Here part of the code as well as the error message obtained in debug mode. On the smartphone the location authorization is OK and network is OK. I restart the smartphone and still the same crash, even though it was working a few days ago.
An idea ?
B4X:
Sub NEW_POSITION 'Geolocalise
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        GeoLoc.Initialize("GeoLocation")
        GeoLoc.GetLocation
        GeoLoc.geoAddress  '(Ligne 63)
        MyLatitude = GeoLoc.Lattitude
        MyLongitude = GeoLoc.Longitude
        Log(GeoLoc.Address)
        'Affiche
        LblLat.Text = "Lat: " & MyLatitude
        LblLong.Text = "Long: " & MyLongitude
        LblAdresse.Text = GeoLoc.Address
    Else
        Activity.Finish
        StartActivity(Main) 'show the main activity again
        ToastMessageShow("Position non trouvée, Problème de réseau ou GPS", True)
    End If
End Sub

Copying updated assets files (40)
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (sourds) Create (first time) **
** Activity (sourds) Resume **
Error occurred on line: 63 (Sourds)
java.io.IOException: frip: DEADLINE_EXCEEDED: deadline exceeded after 4.932716094s. Name resolution delay 0.050917656 seconds. [closed=[], open=[[buffered_nanos=4933385727, waiting_for_connection]]]
at android.location.Geocoder$SynchronousGeocoder.getResults(Geocoder.java:388)
at android.location.Geocoder.getFromLocation(Geocoder.java:134)
at de.donmanfred.GeoLocatorwrapper.geoAddress(GeoLocatorwrapper.java:112)
at b4a.example.sourds$ResumableSub_NEW_POSITION.resume(sourds.java:570)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8913)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
 

TILogistic

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
I looked at the links but I don't see at all what I need to add to my code. Can you help me a little more?
THANKS
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Just like that?
B4X:
Sub NEW_POSITION 'Geolocalise
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        GeoLoc.Initialize("GeoLocation")
        GeoLoc.GetLocation
        GeoLoc.geoAddress  '(Ligne 63)
        MyLatitude = GeoLoc.Lattitude
        MyLongitude = GeoLoc.Longitude
        Log(GeoLoc.Address)
        'Affiche
        LblLat.Text = "Lat: " & MyLatitude
        LblLong.Text = "Long: " & MyLongitude
        LblAdresse.Text = GeoLoc.Address
     [B]   sleep(1000)[/B]
    Else
        Activity.Finish
        StartActivity(Main) 'show the main activity again
        ToastMessageShow("Position non trouvée, Problème de réseau ou GPS", True)
    End If
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
If you make more than one simultaneous request?

Test
B4X:
sleep(1000) 'or Sleep(0)
GeoLoc.geoAddress  '(Ligne 63)
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Ah I understand
It is difficult to test because the crash problem does not occur every day, but probably when the network is not great. So I'm going to test every day and see.
Does Geolocation require network presence all the time or only for 'GeoLoc.geoAddress'.
If I only use 'GeoLoc.Lattitude' and 'GeoLoc.Longitude', is network necessary?
Merci beaucoup
 
Upvote 0

Setlodi

Member
According to your error message, it times out after trying for 4.932716094 seconds. If you're still experiencing problem, maybe increase Sleep to 5000 (5 seconds).
 
Upvote 0
Top