Android Tutorial Google Maps

Discussion in 'Tutorials & Examples' started by Erel, Feb 24, 2016.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User


    Installation instructions:

    - Register your app in Google developer console:
    You need to enable Google Maps Android API.
    Then click on Credentials -> Create Credentials -> API Key -> Android Key.
    You should get a key that looks like: AIzaSyCmFHamGE0O0BvxxxxxxxxXbTCSrjFVg-Q

    - Copy the attached library and put it in the additional libraries folder. Add a reference to the GoogleMaps library.

    - Add this to the manifest editor (replace the value with your key):
    CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)


    "false" />

    Don't add #AdditionalRes or #ExcludeClasses.

    - Set minSdkVersion to 14 (Android 4).

    - Add a MapFragment with the visual designer. It will appear under the CustomView menu. If you don't see it then make sure that the GoogleMaps library is selected.
    You can change the properties from the designer.
    Set the anchors to BOTH so the map will fill the activity:


    Implement the Ready event to get a reference to the GoogleMap object.
    Complete code:
    Sub Process_Globals
    Private rp As RuntimePermissions
    End Sub

    Sub Globals
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    Wait For MapFragment1_Ready
       gmap = MapFragment1.GetMap
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
           gmap.MyLocationEnabled = 
    Log("No permission!")
    End If
    End Sub


    v2.50 - Required dependencies were added to the library.
    My Location Enabled property was removed from the designer as it needs to be set after the permission is granted.
    - v2.02 EXTERNAL_STORAGE permission removed. It is no longer required.
    GetOpenSourceLicenseInfo returns an empty string.
    Fixes an issue with the ready event being lost if the activity is paused before the map is ready.

    Note that you will need to update the package name and api key in the attached example.

    Attached Files:

    Last edited: Aug 21, 2019 at 10:08 AM
  2. fbritop

    fbritop Active Member Licensed User

    I have tried your example but it cannot compile:

    Invalid resource directory name: C:\SDK\Android\tools\..\extras\google\google_play_services\libproject\google-play-services_lib\res/drawable-xxxhdpi

    Part of the manifiest is:

    <uses-sdk android:minSdkVersion=
    "14" android:targetSdkVersion="14"/>
    <supports-screens android:largeScreens=

       <meta-data android:name=
    "@integer/google_play_services_version" />
    key has been replaced with my console value
  3. rscheel

    rscheel Well-Known Member Licensed User

    You need to place your api key.

    android:value="Here's your api key"
  4. fbritop

    fbritop Active Member Licensed User

    Where it says:
    I already have put the correct API key from the console. I just print out with XXXXX no to make it public to the forum
  5. Daniel-White

    Daniel-White Active Member Licensed User

    Sorry, Perhaps I will do a stupid question, what is the improvement, or difference with the old tutorial.?
  6. ricardotm1968

    ricardotm1968 Member Licensed User

    Hi Erel,

    I'm trying to follow your example, follow the steps were as follows:
    1. android SDK-Update
    2. Copy google-play-services and android-support-v4 in additional libraries folder.
    3. Register my project in google and got the API key for android
    4. Copy the text to the manifest, replacing key API
    5. Copy the attributes
    6. Copy all code in an activity.
    When compiling displays the MapFragment but can not find the map
    What will be the error?
  7. vfafou

    vfafou Active Member Licensed User

    I have changed the mapfragment object as this tutorial.
    I'm using the GoogleMapsExtras library (AnimateToBounds) and I've noticed the following problem:
    When I'm in debug mode, it works normally.
    In release mode it does nothing. I can see the map but no movement!
    Is there any suggestion?

    Thank you in advance!
  8. DonManfred

    DonManfred Expert Licensed User

    It is now realized as customView (nees b4a 5.8+)
    Maybe other changes too but i don´t know :)
    Devan and Daniel-White like this.
  9. Anser

    Anser Well-Known Member Licensed User

    My app works fine on GoogleMaps Ver 1.01 but error out when I use ver 2.00, (I rechecked and confirmed that if I go back to ver 1.01, then it is working fine)

    I was using the Google Maps Ver 1.01 as per the old tutorial
    Today I changed to the new version of GoogleMaps ie ver 2.00

    The error is that the Map object is accessed before it is initialized, but the same code is working fine if I use ver 1.01

    Is there a minimum version for the Google Play Services to be used along with this version of GoogleMaps ?

    As of now I am using Google Play Services ver 28, I know that ver 29 is available, but haven't upgraded it as I read discussions regarding few bugs in Android Support Library and AppCompat etc. So I am waiting for a bug free version of Android Support Library. I believe that I can upgrade just the Google Play Service alone.

    I already have the API Key, I hope that I don't have to use a new API Key to use GoogleMaps ver 2.00

  10. MetalOS

    MetalOS Member Licensed User


    I followed the tutorial but the Google map remains white and no tile is loaded. here's a screenshot to show you the problem.

  11. DonManfred

    DonManfred Expert Licensed User

  12. MetalOS

    MetalOS Member Licensed User

    I had not seen this post. Thank you.
  13. MetalOS

    MetalOS Member Licensed User

    I solved my problem. I select my bad api developer console, now that I've selected the correct all works.
    DonManfred likes this.
  14. stanks

    stanks Active Member Licensed User

    in that Erel example from first to remove marker and show another one on anther position?
  15. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
  16. fbritop

    fbritop Active Member Licensed User

    Has someone has got this error and how to fix it?

    B4A version: 5.80
    Parsing code.    (
    Running custom action.    (
    Compiling code.    (
    Compiling layouts code.    (
    Generating R 
    file.    Error
    invalid resource directory name: c:\sdk\android\extras\google\google_play_services\libproject\google-play-services_lib\res/drawable-xxxhdpi
    I have double checked than "c:\sdk\android\extras\google\google_play_services\libproject\google-play-services_lib\res" exists
    My manifiest has:
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14"/>
    Api key is correct

    Additional Libraries folder contains: android-support-v4.jar; GoogleMaps.jar; GoogleMaps.xml; google-play-services.jar;

    Cannot seem to find where is the error. Any help?
  17. analizer3816

    analizer3816 Member Licensed User

    why mapfragment cannot set position(left,top,width,height) with code
  18. Erel

    Erel Administrator Staff Member Licensed User

    Do you see this folder <sdk path>\extras\google\google_play_services\libproject\google-play-services_lib\res\drawable-xxxhdpi ?

    The correct way to set its layout is with the designer. MapFragment is not a view. If you need to move it at runtime then put it in a panel and move the panel.
  19. Rockefeller Goldman

    Rockefeller Goldman Active Member Licensed User

    I too don't have this Folder Erel, even after installing Google Play Services with AVD Manager.

    This ERROR appears: AndroidManifest.xml:33: error: Error: No resource found that matches the given name (at 'value' with value '@Integer/google_play_services_version').

    אנא עזור
  20. Erel

    Erel Administrator Staff Member Licensed User

    AVD manager is not relevant. Try to update to the latest version of google play services. Make sure to later copy the updated jar file to the additional libraries folder.
Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice