Android Tutorial Google Maps

Status
Not open for further replies.
upload_2016-2-24_12-2-46.png



Installation instructions:

- Register your app in Google developer console: https://console.developers.google.com
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):
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)

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

AddApplicationText(
<uses-library
      android:name="org.apache.http.legacy"
      android:required="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:

SS-2016-02-24_12.13.18.png



Implement the Ready event to get a reference to the GoogleMap object.
Complete code:
B4X:
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)
   Activity.LoadLayout("1")
   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

Notes


Updates

-
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.
 

Attachments

  • GoogleMapsExample.zip
    8.4 KB · Views: 3,671
  • GoogleMaps.zip
    19.4 KB · Views: 3,927
Last edited:

MODERN TALKING

Active Member
Licensed User
Longtime User
תודה אֶרְאֵל

Compiles perfectly now BUT:

The dreaded WHITE BLANK TILES with NO MAP showing.
 

MODERN TALKING

Active Member
Licensed User
Longtime User
What is a Signing Key? I thought only need an API Key.

I'm moving to Bangalore man - where EVERYONE is a Programmer. Hire about 1,000 of 'em.
 

jchal

Active Member
Licensed User
Longtime User
when i try to run the example i get this erorr why?
B4A version: 5.80
Parsing code. (0.00s)
Compiling code. (0.05s)
Compiling layouts code. (0.00s)
Generating R file. Error
ERROR: resource directory 'C:\android\tools\..\extras\google\google_play_services\libproject\google-play-services_lib\res' does not exist
 

jchal

Active Member
Licensed User
Longtime User
it neede to down load google play services
now i am facing this error
B4A version: 5.80
Parsing code. (0.00s)
Compiling code. (0.12s)
Compiling layouts code. (0.00s)
Generating R file. (0.60s)
Compiling debugger engine code. (1.25s)
Compiling generated Java code. Error
Cannot find: C:\Program Files (x86)\Anywhere Software\Basic4android\libraries\google-play-services.jar
 

Alisson

Active Member
Licensed User
Erel, hello!
You can publish how develop cluster and using Json to take resulted of the database?
I try develop one app like geolocation whatsapp, but not have sucessuful!

Thanks very much!
 

jchal

Active Member
Licensed User
Longtime User
i have the soloution , i did some thing odd,
i went whre the sdk is and copy the jar file and the google-play-services.jar.properties into the C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries
and i compile and run the software ..............;););););););)
i know it is odd but it works
it is time to play now !!!!!!
 

jchal

Active Member
Licensed User
Longtime User
i have the soloution , i did some thing odd,
i went whre the sdk is and copy the jar file and the google-play-services.jar.properties into the C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries
and i compile and run the software ..............;););););););)
i know it is odd but it works
 

klaus

Expert
Licensed User
Longtime User
You should not add google-play-services.jar to the C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries folder
but to your AdditionalLibraries folder.
If you don't already have one you should add one.
Why ? Because if you update B4A in the same folder as the previous version the Libraries folder will be replaced with the 'standard' B4A libraries and all additional libraries you added will be lost.
You must reference the AdditionalLibraries folder in the IDE in the Tools menu.

upload_2016-3-17_17-51-2.png


And enter the folder name in the AdditionalLibraries field.

upload_2016-3-17_17-52-34.png
 

Attachments

  • upload_2016-3-17_17-51-58.png
    upload_2016-3-17_17-51-58.png
    23.2 KB · Views: 428

RichardN

Active Member
Licensed User
Longtime User
I have a mature project that I am updating after the B4A Ver 5.8 changes.

- All my SDK resources appear up to date.
- The manifest appears unchanged from before and already contains my existing API signature for the package as in the example.
- I have added the module attributes and the program runs right to the point where you invoke a map when I get a run-time error evidently from a missing resource:

Installing file........

** Activity (main) Resume **
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/GoogleApiAvailability;
at anywheresoftware.b4a.objects.MapFragmentWrapper.IsGooglePlayServicesAvailable(MapFragmentWrapper.java:92)
at com.xxxxxxx.yyyyy.zzzz.main._btnshowmap_click(main.java:996)
at java.lang.reflect.Method.invoke(Native Method)................................


Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.GoogleApiAvailability" on path: DexPathList[[zip file "/mnt/asec/com.xxxxxxx.yyyyy.zzzz-6/base.apk"],nativeLibraryDirectories=[/mnt/asec/com.xxxxxxx.yyyyy.zzzz-6/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 21 more
Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.common.GoogleApiAvailability
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 22 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

This appears to me a missing resource. What is it and where should it be located ?
 

sdixon

Member
Licensed User
Longtime User
I also am getting the same error as described above.

Followed all of the instructions and when compiling get the error message

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

I just downloaded and installed the latest version of the Android SDK
 

RichardN

Active Member
Licensed User
Longtime User
The Additional libraries folder contains:

google-play-services.jar
google-play-services.properties

The folder is correctly referenced at Tools > Configure Paths > Additional Libraries

The resource targeted at....
#AdditionalRes: C:\Android-SDK\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
.... is not evident in the target folder

What exactly does 'com.google.android.gms' look like? The folder in question contains no files only more folders....
Volume in drive C is Windows8_OS
Volume Serial Number is 5082-E8DC

Directory of C:\Android-SDK\extras\google\google_play_services\libproject\google-play-services_lib\res

22/03/2016 19:01 <DIR> .
22/03/2016 19:01 <DIR> ..
08/02/2016 21:21 <DIR> color
08/02/2016 21:21 <DIR> drawable
08/02/2016 21:21 <DIR> drawable-hdpi
08/02/2016 21:21 <DIR> drawable-mdpi
08/02/2016 21:21 <DIR> drawable-tvdpi
08/02/2016 21:21 <DIR> drawable-xhdpi
08/02/2016 21:21 <DIR> drawable-xxhdpi
08/02/2016 21:21 <DIR> drawable-xxxhdpi
08/02/2016 21:21 <DIR> layout
08/02/2016 21:21 <DIR> layout-v21
08/02/2016 21:21 <DIR> raw
08/02/2016 21:21 <DIR> values
08/02/2016 21:21 <DIR> values-af
08/02/2016 21:21 <DIR> values-am
08/02/2016 21:21 <DIR> values-ar
08/02/2016 21:21 <DIR> values-az-rAZ
08/02/2016 21:21 <DIR> values-bg
08/02/2016 21:21 <DIR> values-bn-rBD
08/02/2016 21:21 <DIR> values-ca
08/02/2016 21:21 <DIR> values-cs
08/02/2016 21:21 <DIR> values-da
08/02/2016 21:21 <DIR> values-de
08/02/2016 21:21 <DIR> values-el
08/02/2016 21:21 <DIR> values-en-rAU
08/02/2016 21:21 <DIR> values-en-rGB
08/02/2016 21:21 <DIR> values-en-rIN
08/02/2016 21:21 <DIR> values-es
08/02/2016 21:21 <DIR> values-es-rUS
08/02/2016 21:21 <DIR> values-et-rEE
08/02/2016 21:21 <DIR> values-eu-rES
08/02/2016 21:21 <DIR> values-fa
08/02/2016 21:21 <DIR> values-fi
08/02/2016 21:21 <DIR> values-fr
08/02/2016 21:21 <DIR> values-fr-rCA
08/02/2016 21:21 <DIR> values-gl-rES
08/02/2016 21:21 <DIR> values-gu-rIN
08/02/2016 21:21 <DIR> values-hi
08/02/2016 21:21 <DIR> values-hr
08/02/2016 21:21 <DIR> values-hu
08/02/2016 21:21 <DIR> values-hy-rAM
08/02/2016 21:21 <DIR> values-in
08/02/2016 21:21 <DIR> values-is-rIS
08/02/2016 21:21 <DIR> values-it
08/02/2016 21:21 <DIR> values-iw
08/02/2016 21:21 <DIR> values-ja
08/02/2016 21:21 <DIR> values-ka-rGE
08/02/2016 21:21 <DIR> values-kk-rKZ
08/02/2016 21:21 <DIR> values-km-rKH
08/02/2016 21:21 <DIR> values-kn-rIN
08/02/2016 21:21 <DIR> values-ko
08/02/2016 21:21 <DIR> values-ky-rKG
08/02/2016 21:21 <DIR> values-lo-rLA
08/02/2016 21:21 <DIR> values-lt
08/02/2016 21:21 <DIR> values-lv
08/02/2016 21:21 <DIR> values-mk-rMK
08/02/2016 21:21 <DIR> values-ml-rIN
08/02/2016 21:21 <DIR> values-mn-rMN
08/02/2016 21:21 <DIR> values-mr-rIN
08/02/2016 21:21 <DIR> values-ms-rMY
08/02/2016 21:21 <DIR> values-my-rMM
08/02/2016 21:21 <DIR> values-nb
08/02/2016 21:21 <DIR> values-ne-rNP
08/02/2016 21:21 <DIR> values-nl
08/02/2016 21:21 <DIR> values-pa-rIN
08/02/2016 21:21 <DIR> values-pl
08/02/2016 21:21 <DIR> values-pt
08/02/2016 21:21 <DIR> values-pt-rBR
08/02/2016 21:21 <DIR> values-pt-rPT
08/02/2016 21:21 <DIR> values-ro
08/02/2016 21:21 <DIR> values-ru
08/02/2016 21:21 <DIR> values-si-rLK
08/02/2016 21:21 <DIR> values-sk
08/02/2016 21:21 <DIR> values-sl
08/02/2016 21:21 <DIR> values-sq-rAL
08/02/2016 21:21 <DIR> values-sr
08/02/2016 21:21 <DIR> values-sv
08/02/2016 21:21 <DIR> values-sw
08/02/2016 21:21 <DIR> values-ta-rIN
08/02/2016 21:21 <DIR> values-te-rIN
08/02/2016 21:21 <DIR> values-th
08/02/2016 21:21 <DIR> values-tl
08/02/2016 21:21 <DIR> values-tr
08/02/2016 21:21 <DIR> values-uk
08/02/2016 21:21 <DIR> values-ur-rPK
08/02/2016 21:21 <DIR> values-uz-rUZ
08/02/2016 21:21 <DIR> values-v11
08/02/2016 21:21 <DIR> values-v21
08/02/2016 21:21 <DIR> values-vi
08/02/2016 21:21 <DIR> values-zh-rCN
08/02/2016 21:21 <DIR> values-zh-rHK
08/02/2016 21:21 <DIR> values-zh-rTW
08/02/2016 21:21 <DIR> values-zu
1 File(s) 0 bytes
94 Dir(s) 381,034,835,968 bytes free

The full run-time log:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/GoogleApiAvailability;
at anywheresoftware.b4a.objects.MapFragmentWrapper.IsGooglePlayServicesAvailable(MapFragmentWrapper.java:92)
at com.xxxxxx.yyyyyyy.main._btnshowmap_click(main.java:996)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:336)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10814)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.GoogleApiAvailability" on path: DexPathList[[zip file "/mnt/asec/com.xxxxxx.yyyyyyy-1/base.apk"],nativeLibraryDirectories=[/mnt/asec/com.xxxxxx.yyyyyyy-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 21 more
Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.common.GoogleApiAvailability
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 22 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
 
Last edited:

MichalK73

Active Member
Licensed User
Longtime User
I loaded a few points close to each other. Points are displayed, however, I see the map on a scale that I can see the whole earth. How do I stop increased to the first point of the set magnification?

Ok. I find and working fine

B4X:
    Dim aa As CameraPosition
    aa.Initialize(first_x,firsy_y,1000)
    gmap.AnimateCamera(aa)
 
Last edited:

sdixon

Member
Licensed User
Longtime User
I uninstalled the Android-sdk. Then I installed Android Studio (which includes the sdk). I then made sure that all of the Android sdk tools were also installed to the latest version. Copied google-play-services.jar to the Additional libraries folder. copied the GoogleMaps library to the Additional Libraries folder, checked it to use it in the app.

Still got the error.

Finally solved it by updating Tools | Configure Paths and then setting the javac.exe path and the android.jar path to the latest (updated) local paths.

A day in which you don't learn something new is not really a good day, so thanks for giving me a good day. paths.png
 

RichardN

Active Member
Licensed User
Longtime User
@Erel.....

Mystery solved. The Google Play Services Library in the <Additional Libraries folder> was completely the correct version.

......However there was an older version of the same library lurking the <Libraries> folder and seemingly the older one was getting picked up by default.

Don't make the same mistake folks..............
 
Status
Not open for further replies.
Top