Android Question Google Maps Implementation

swabygw

Active Member
Licensed User
Longtime User
I'm having a bit of trouble trying to implement GoogleMaps, as here: https://www.b4x.com/android/forum/threads/google-maps.63930/#content

I've followed those instructions (by creating a new, blank project), but keep getting the ToastMessage: "Please install Google Play Services."

I know it's a bit vague, but I didn't want to upload the .zip file of the project since it has my API key in it, but any ideas? My manifest looks like this:

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="19"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
'************ 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) ************
AddApplicationText(
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCGKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "/> (my API key is in here)
)

I should add that my Project Attributes looks like this:

B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#AdditionalJar: com.google.android.gms:play-services-maps
#AdditionalRes: C:\Users\FirstName LastName\AppData\Local\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
#End Region

When I added the last line, the ToastMessage went away, but no map shows up. Also, I have to mention that that directory doesn't actually exist on my machine when going to it in Windows Explorer (I have up to the google_play_services folder, but not libprojects folder).
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
I'm still installing some lower-version platforms, but the necessary folder isn't appearing. Here's how my directory looks:
upload_2017-6-21_16-2-27.png


The libproject folder isn't showing up. Here's how my SDK Mgr looks (the checked items are almost done installing):
upload_2017-6-21_16-4-21.png
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
So, I've followed the instructions here: https://www.b4x.com/android/forum/t...e-play-services_lib-res-does-not-exist.67126/ , #5, to uninstall Google Play services, download, and put v29 files into correct place. My attributes look like this now:
B4X:
#AdditionalJar: com.google.android.gms:play-services-maps
#AdditionalRes: C:\AndroidSDK\extras\google\google-play-services\libproject\google-play-services_lib\res,com.google.android.gms
Manifest looks the same as earlier. Got error that looks like this:
upload_2017-6-21_17-45-22.png
I'm at a loss. It looks like there needs to be settings set correctly in: a) Project Attributes, b) Manifest Editor, and c) Configure Paths - Additional Libraries. I've tried all different combinations of these with no success.
 
Last edited:
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
I'm still having error on compiling a step "Generating R file. Error". Here's my setup (let me know if I should provide more images/info):
*Btw, I've also get the same error when running it on my Sony Xperia device.

Emulator
upload_2017-6-22_3-35-7.png

Extra in SDK
upload_2017-6-22_3-6-54.png

Paths Configuration
upload_2017-6-22_2-59-43.png

Additional Libraries Folder

upload_2017-6-22_3-2-39.png

Manifest Editor
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="19"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
'************ 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) ************
AddApplicationText(
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCGKGliYwm_9uV_XXX "/>
)
Code:
B4X:
#Region Project Attributes
  #ApplicationLabel: B4A Example
  #VersionCode: 1
  #VersionName:
  'SupportedOrientations possible values: unspecified, landscape or portrait.
  #SupportedOrientations: unspecified
  #CanInstallToExternalStorage: False
  #AdditionalJar: com.google.android.gms:play-services-maps
#End Region

#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.
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("Layout1")
  If MapFragment1.IsGooglePlayServicesAvailable = False Then
    ToastMessageShow("Please install Google Play Services.", True)
  End If
End Sub

Sub MapFragment1_Ready
  gmap = MapFragment1.GetMap
  Dim m1 As Marker = gmap.AddMarker(10, 30, "test")
  m1.Snippet = "This is the snippet"
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
Last edited:
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
Thought it might help if I upload my project, so here it is (I've simply removed the API key from the manifest).
 

Attachments

  • MapExample.zip
    8.4 KB · Views: 133
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
Good news - after many hours, I got it working on my handheld device (Sony Xperia).

I've also got the app almost starting up on the emulators. The critical step was that whenever a different emulator is used, the API # mentioned in the second box (the android.jar path) of the Configure Paths dialog must match the API # of the emulator, or get the "Generating R file. Error" (this gives a bit of an illusion that it's working and something in the code/manifest must be wrong). I say "almost" starting up because the app starts, but complains about either the Play Store is missing or Play Services not being installed. I attempted to resolve this by copying the google-play-services.jar file into the Additional Libraries directory, but that hasn't had succeeded (although, in some emulators, it mentioned that it was looking for a higher version of Google Play Services, but my version was just downloaded a few hours ago). Also discovered that the x86 system images with the Google API's (https://software.intel.com/en-us/bl...android-sdk-x86-system-image-with-google-apis) are not available as a choice when creating an emulator, despite them being downloaded in the SDK (I read somewhere that this is a bug in the emulator creation dialog, but not sure). So, the versions of the emulators that are NOT x86 (i.e., armeabi images) might work fine with Play Store/Services, but the startup is so long, I gave up on them...I'll wait until the x86 version is properly available since x86 uses HAXM and starts up much faster.

I should also mention that API 24 and API 26 don't work...if you use Google Play Intel Atom (x86) as the CPU - those were the only two APIs that had this as a choice for CPU (and I suspect that these would have resolved the Play Services/Store issues). The reason is that the ADB_VENDOR_KEYS file never gets the vendor/revision ID entered in it since the device is an emulator. Thus, the ADB always views it as unauthorized. Just leave it alone and use a different version/CPU.

So, at least it works on the handheld device. But, is there a particular emulator x86 configuration, or some action to take, for Play Services/Store to work on the emulator?
 
Last edited:
Upvote 0

Similar Threads

Top