I get the following error running on Android 6+:
My Manifest:
The error is generated in this sub:
I have registered the API on the Google Developers Console.
B4X:
java.lang.RuntimeException: Object should first be initialized (GoogleMap).
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.MANAGE_DOCUMENTS)
AddApplicationText(
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBnI9CipMS2Nb6HwVtT-0TUgjVkyzVYUIs"/>
)
'************ Google Play Services Base ************
AddApplicationText(
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:exported="false"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
)
'************ Google Play Services Base (end) ************
'End of default text.
B4X:
Sub btnNearest_Click
Dim CurrentLat As Double
Dim CurrentLon As Double
Dim Curs As Cursor
Curs = Starter.SQL0.ExecQuery("SELECT * FROM config")
Curs.Position = 0
CurrentLat = Curs.GetDouble("lat")
CurrentLon = Curs.GetDouble("lon")
Curs.close
LogColor("Current Lat: " & CurrentLat, Colors.Red)
LogColor("Current Lon: " & CurrentLon, Colors.Red)
If CurrentLat = 0 And CurrentLon = 0 Then
ToastMessageShow("You have no Current Coordinates", False)
Else
Dim c As Cursor
c = Starter.SQL0.ExecQuery("Select * from stations where (lat) and (lon) order by (abs(lon -(" & CurrentLon & ")) +( abs(lat -(" & CurrentLat & "))*1)) Limit 2;")
LogColor("Records: " & c.RowCount, Colors.Blue)
For i = 0 To c.RowCount - 1
c.Position = i
LogColor("Nearest : " & c.GetString("saps"), Colors.Blue)
LogColor("Nearest Lat: " & c.GetString("lat"), Colors.Blue)
LogColor("Nearest Lon: " & c.GetString("lon"), Colors.Blue)
Log(CRLF)
Dim Lat As Double
Dim Lon As Double
Lat = c.GetString("lat")
Lon = c.GetString("lon")
Dim MarkerText As String = "SAPS"
Dim ExtraText As String = c.GetString("saps")
gmap1 = MapFragment1.GetMap
Dim m1 As Marker = gmap1.AddMarker(Lat, Lon, MarkerText) '<< java.lang.RuntimeException: Object should first be initialized (GoogleMap).
Dim CameraPosition1 As CameraPosition
CameraPosition1.Initialize(Lat, Lon, 10)
gmap1.AnimateCamera(CameraPosition1)
m1.Snippet = ExtraText
Next
pnlMap.Visible = True
End If
I have registered the API on the Google Developers Console.