Android Tutorial [B4X] [B4XPages] GoogleMaps example

1594642169087.png


Example of showing a Google map, in a cross platform B4XPages project. The APIs of the three GoogleMaps libraries are quite different from one another, so we need to use platform specific code for the map creation. Still, it is quite simple to further extend this project and build a cross platform solution.

A different key is required for each platform:
B4A - https://www.b4x.com/android/forum/threads/google-maps.63930/#content
B4J - https://www.b4x.com/android/forum/threads/56744/#content
B4i - https://www.b4x.com/android/forum/threads/47019/#content

In B4i you need to add GoogleMaps.bundle to B4i\Files\Special. It was removed as it is too big for the forum. You can find it in the example project from the above tutorial.

Note that there was an issue in iGoogleMaps v1.41. It was fixed in the hosted builders and will be included in the local builders of B4i v6.80.
 

Attachments

  • Project.zip
    10 KB · Views: 2,311

TILogistic

Expert
Licensed User
Longtime User
b4a and b4j very good.

note: you Api KEY ?? :rolleyes:
b4j


no problem use.
 
Last edited by a moderator:

Beja

Expert
Licensed User
Longtime User
View attachment 97060

Example of showing a Google map, in a cross platform B4XPages project. The APIs of the three GoogleMaps libraries are quite different from one another, so we need to use platform specific code for the map creation. Still, it is quite simple to further extend this project and build a cross platform solution.

A different key is required for each platform:
B4A - https://www.b4x.com/android/forum/threads/google-maps.63930/#content
B4J - https://www.b4x.com/android/forum/threads/56744/#content
B4i - https://www.b4x.com/android/forum/threads/47019/#content

In B4i you need to add GoogleMaps.bundle to B4i\Files\Special. It was removed as it is too big for the forum. You can find it in the example project from the above tutorial.

Note that there was an issue in iGoogleMaps v1.41. It was fixed in the hosted builders and will be included in the local builders of B4i v6.80.

Perfect.. I tested the b4j version.. working like a charm.. code is simple and short -perfect for learning!
Thanks boss!
 

edgardomf

Member
Licensed User
Longtime User
Hola a todos, desde ya muchas gracias por los trabajos realizados en B4X.
Estoy tratando de manejar el GoogleMaps con B4A Ver 9.90 pero aunque probablemente todo lo realizado en
B4A - https://www.b4x.com/android/forum/threads/google-maps.63930/#content
y ademas el ejemplo Proyect.zip contenido aqui.
Siempre tengo el mismo inconveniente, No me muestra el mapa Inicial ni cuando presiono un lugar, aparece en Blanco.
Cuando copie el proyecto de B4A antes que este con gmap.MyLocation, me aparece bien Lon. y Lat. ...
Que puede ser.?
 

TILogistic

Expert
Licensed User
Longtime User
Hola a todos, desde ya muchas gracias por los trabajos realizados en B4X.
Estoy tratando de manejar el GoogleMaps con B4A Ver 9.90 pero aunque probablemente todo lo realizado en
B4A - https://www.b4x.com/android/forum/threads/google-maps.63930/#content
y ademas el ejemplo Proyect.zip contenido aqui.
Siempre tengo el mismo inconveniente, No me muestra el mapa Inicial ni cuando presiono un lugar, aparece en Blanco.
Cuando copie el proyecto de B4A antes que este con gmap.MyLocation, me aparece bien Lon. y Lat. ...
Que puede ser.?

Post this here, there are members in Spanish who can help.

 

Lakhtin_V

Active Member
Licensed User
Longtime User
I'm trying to see the map on the screen. I did everything as in your example, but an error appears

1670838158171.png

1670838262101.png


Google map:
#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.
[B]    Private gmap As GoogleMap
    Private MapFrag As MapFragment
    Private pnl As Panel[/B]
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")
[B]    pnl.Initialize("")
    Activity.AddView(pnl,0%x,0%y,100%x,100%y)
    MapFrag.Initialize("MapFrag",pnl)
  
    Wait For MapFrag_Ready
    gmap = MapFrag.GetMapEnd Sub[/B]

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub MapFrag_Click (Point As LatLng)
    gmap.AddMarker(Point.Latitude, Point.Longitude, "New Marker")
End Sub

Manifrst Editor

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="19" android:targetSdkVersion="30"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
'SetApplicationAttribute(android:icon, "@icon")
SetApplicationAttribute(android:label, "Giperbola")
SetApplicationAttribute(android:largeHeap,"true")
SetApplicationAttribute(android:usesCleartextTraffic,"true")
CreateResourceFromFile(Macro, Themes.LightTheme)
AddPermission("android.permission.ACCESS_NOTIFICATION_POLICY")
AddPermission("android.permission.MOUNT_UNMOUNT_FILESYSTEMS")
AddPermission("android.permission.ACCESS_NETWORK_STATE")
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.RECORD_AUDIO")
'AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.RECORD_AUDIO")
AddPermission("android.permission.ACCESS_FINE_LOCATION")

[B]CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIzaSyAaphCMm3ns-2TQQQQQQQQQQQQQQQQQQQW5dc4"/>
)
AddApplicationText(
<uses-library
      android:name="org.apache.http.legacy"
      android:required="false" />
)[/B]
 
Top