Android Question Geocoder library error

ivanomonti

Expert
Licensed User
Longtime User
error (GeocoderDemo)

B4X:
Logger connesso a: emulator-5554
java.lang.NoClassDefFoundError: com.google.android.gms.common.GoogleApiAvailability
    at anywheresoftware.b4a.objects.MapFragmentWrapper.IsGooglePlayServicesAvailable(MapFragmentWrapper.java:92)
    at b4a.example.panel_01._initialize(panel_01.java:182)
    at b4a.example.main._activity_create(main.java:375)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: com.google.android.gms.common.GoogleApiAvailability
    at anywheresoftware.b4a.objects.MapFragmentWrapper.IsGooglePlayServicesAvailable(MapFragmentWrapper.java:92)
    at b4a.example.panel_01._initialize(panel_01.java:182)
    at b4a.example.main._activity_create(main.java:375)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
Copying updated assets files (2)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
Copying updated assets files (2)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
Copying updated assets files (2)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
**********
No results found
**********
No results found

I can not understand,
Android B4x 7.30
android emulator as I do not have a device
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is not related to Android SDK. The library that you are using depends on Google Play Services "app" being installed on the device. I recommend you to use a real device it will be simpler.

You can also call Google geocoding REST API. It is quite simple:

B4X:
Sub PlaceToLatLon(Place As String) As ResumableSub
   Dim res() As Double = Array As Double(9999, 9999)
   Dim j As HttpJob
   j.Initialize("", Me)
   j.Download2("https://maps.googleapis.com/maps/api/geocode/json", Array As String("key", API_KEY, "address", Place))
   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
     Dim jp As JSONParser
     jp.Initialize(j.GetString)
     Dim m As Map = jp.NextObject
     If m.Get("status") = "OK" Then
       Dim results As List = m.Get("results")
       If results.Size > 0 Then
         Dim first As Map = results.Get(0)
         Dim geometry As Map = first.Get("geometry")
         Dim location As Map = geometry.Get("location")
         res(0) = location.Get("lat")
         res(1) = location.Get("lng")
       End If
     End If
   Else
     Log("Error!")
   End If
   j.Release
   Return res
End Sub

Usage example:
B4X:
Wait For(PlaceToLatLon("Israel Yodfat")) Complete (ll() As Double)
If ll(0) <> 9999 Then
   Log("Location: " & ll(0) & ", " & ll(1))
Else
  Log("Failed to geocode")
End If

Get the API key here: https://developers.google.com/maps/documentation/geocoding/get-api-key
 
Upvote 0
Top