Android Question [SOLVED] Google maps always blank

Nas9

Member
Licensed User
Longtime User
Hello everybody,
I have a problem with Google maps, it displays the controls with blank background like this


blankGM.PNG


I followed the instructions in this thread:
https://www.b4x.com/android/forum/threads/google-maps.63930/

I made an API key with the app package name, SHA-1 code
then add it to the manifest

this is the code
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private rp As RuntimePermissions
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("mapview")
    Wait For MapFragment1_Ready
    gmap = MapFragment1.GetMap

    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        gmap.MyLocationEnabled = True
    Else
        Log("No permission!")
    End If
End Sub

I also tried the example and got the same output.
can you help me please?
 

Nas9

Member
Licensed User
Longtime User
Post you manifest code. You can replace your key with xxxx.


Probably the key is not valid. Or the manifest is not correct.
APIKey.PNG
Hi DonManfred,
Here is the manifest:
Manifest:
'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="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)

AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIzaSyB4Ec4c97ANj1TN5JEeBDcokF5XXXXXXXX"/>
)

AddApplicationText(
<uses-library
      android:name="org.apache.http.legacy"
      android:required="false" />
)
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
My two cents:
A blank map is 99,9% an API_Key problem. Try to generate a new one without restrictions.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Do you have the Mapfragment_ready event ? Add a log after "Wait For MapFragment1_Ready" to check it
 
Upvote 0

Nas9

Member
Licensed User
Longtime User
I added log after each line
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private rp As RuntimePermissions
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("mapview")
    Wait For MapFragment1_Ready
    Log("Step 2")
    gmap = MapFragment1.GetMap
    Log("Step 3")
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        gmap.MyLocationEnabled = True
        Log("Step 4")
    Else
        Log("No permission!")
    End If
End Sub

Sub MapFragment1_Ready
    Log("Step 1")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

The result
Rich (BB code):
Step 2
Step 3
Step 4

 
Upvote 0

Nas9

Member
Licensed User
Longtime User
The problem has been solved!

Maps SDK for Android was disabled on Google cloud platform, I needed to enable it before using the key.

Thanks to everyone for help.
 
Upvote 0
Top