B4A Library GoogleMapsExtras

GoogleMapsExtras is an ongoing project to implement more of the Google Maps Android v2 classes in Basic4Android.

Currently the library allows you to create these objects:

Tutorials for each object will be uploaded to the Google Maps Android v2 tutorial thread.

Martin.


Edit (Erel): proguard rules for R8 optimizer: https://www.b4x.com/android/forum/t...apsextras-2-00-setzoomcontrolsenabled.172313/
 

Attachments

Last edited by a moderator:
Hi,
I'm trying to work with wms server via CustomUrlTileProvider. All work great until i try this adress:
B4X: Copy
http://integracja.gugik.gov.pl/cgi-bin/KrajowaIntegracjaEwidencjiGruntow?VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=powiaty,powiaty_obreby,ekw,regon,pesel,zsin,obreby,dzialki,geoportal,numery_dzialek,budynki&SRS=EPSG:4326&WIDTH=256&HEIGHT=256&TRANSPARENT=TRUE&FORMAT=image/png&BBOX=18.08074951171875,52.07781801208549,18.08349609375,52.079506003796965&styles=
This WMS server uses redirections and finally get image from:
B4X: Copy
https://konin.geoportal2.pl/map/geoportal/wms.php?LAYERS=dzialki,budynki&REQUEST=GetMap&SERVICE=WMS&FORMAT=image/png&STYLES=,&HEIGHT=256&VERSION=1.1.1&SRS=EPSG:2180&WIDTH=256&BBOX=437022.374350923,468358.349568826,437212.163431718,468547.668771142&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_xml.
This second adress i see in browser after redirect from first - i think that there is more than one redirection.
Is it possible that CustomUrlTileProvider don't accept redirections?

Regards
 
Thank you for response. Very strange problem. I made more tests and i'm almost sure that problem comes from redirections or some weird WMS server configurations. Thanks again.
 
Morning, I need a littel hand here:

I am doing my 1st steps with the GoogleMapsExtras library and I ran prompt into a problem :(

assuming I draw a circle on the map like this:

B4X: Copy
Dim co As CircleOptions
co.Initialize
co.Center2(0, 0).Radius(spnRadius.SelectedItem).FillColor(Colors.ARGB(90,158,0,255)).StrokeColor(Colors.ARGB(126,158,0,204)).StrokeWidth(3)
Dim Circle1 As Circle
Circle1 = gmapExtra.AddCircle(gmap, co)
Log(Circle1.Id) ' show me the circle id
Circle1.Remove ' remove the circle - redraw the map?
Log(Circle1.Id) ' should raise an exception as the circle is gone?

how can I remove the circle, using
B4X: Copy
Circle1.Remove
does not work

can somebody explain what I am doing wrong or how to do it ?


THX
 
@warwound
Hi,
Is it possible to customize the InfoWindow that is displayed? Like changing the color, border radius, etc.
Thank you!
 
Hello
Why I cannot remove Circle? what is the code ? "gmapExtra.Remove" is wrong.
Thank you

Code: Copy
Private gmapExtra As GoogleMapsExtras
Private co As CircleOptions

'Add Circle'
    co.Initialize
    co.Center2(Lati, Longi).Radius(3000).FillColor(Colors.ARGB(50,50,220,125)).StrokeColor(Colors.Black)
    gmapExtra.AddCircle(gmap, co)
    
'And now Remove Circle'   
    gmapExtra.Remove
 
Hello
Why I cannot remove Circle? what is the code ? "gmapExtra.Remove" is wrong.
Thank you

Code: Copy
Private gmapExtra As GoogleMapsExtras
Private co As CircleOptions

'Add Circle'
    co.Initialize
    co.Center2(Lati, Longi).Radius(3000).FillColor(Colors.ARGB(50,50,220,125)).StrokeColor(Colors.Black)
    gmapExtra.AddCircle(gmap, co)
  
'And now Remove Circle' 
    gmapExtra.Remove

Dim c As Circle
c = gmapExtra.AddCircle(gmap, co)
c.Remove

see:
 
Hello
Why I cannot remove Circle? what is the code ? "gmapExtra.Remove" is wrong.
Thank you

Code: Copy
Private gmapExtra As GoogleMapsExtras
Private co As CircleOptions

'Add Circle'
    co.Initialize
    co.Center2(Lati, Longi).Radius(3000).FillColor(Colors.ARGB(50,50,220,125)).StrokeColor(Colors.Black)
    gmapExtra.AddCircle(gmap, co)
   
'And now Remove Circle'  
    gmapExtra.Remove
see:

B4X: Copy
    Dim CircleOptions1 As CircleOptions
    Dim Circle1 As Circle 'Optional global variable
    CircleOptions1.Initialize
    CircleOptions1.Center2(MapLatitude, MapLongitude).Radius(300).FillColor(Colors.ARGB(150, 255, 229, 179)).StrokeColor(Colors.ARGB(150, 240, 58, 23)).StrokeWidth(2.0)
    Circle1 = GoogleMapsExtras1.AddCircle(GoogleMap1, CircleOptions1)
'    remove
    Circle1.Remove

sample:
 

Attachments

  • 1.gif
    1.gif
    388.9 KB · Views: 847
OK here's my first version of a wrapper for the KML packages in the Android Maps Utils.
The classes and methods i have wrapped so far are:

AndroidMapsUtils
Comment:
http://googlemaps.github.io/android-maps-utils/javadoc/
Author: Martin Pearman
Version: 0.01
  • KMLLayer
    Methods:
    • AddLayerToMap
    • GetContainers As List
    • GetPlacemarks As List
    • HasContainers As Boolean
    • HasPlacemarks As Boolean
    • Initialize (GoogleMap1 As GoogleMap, InputStream1 As InputStream)
    • Initialize2 (GoogleMap1 As GoogleMap, ResourceId As Int)
    • IsInitialized As Boolean
    • IsLayerOnMap As Boolean
    • RemoveLayerFromMap
  • Properties:
    • Map As GoogleMap
  • KmlContainer
    Methods:
    • GetContainers As List
      Gets a List of nested KmlContainers.
    • GetPlacemarks As List
      Gets a List of KmlPlacemarks.
    • GetProperty (PropertyName As String) As String
      Gets a single property value for the given property name.
    • GetStyle (StyleId As String) As KmlStyle
      Gets a style for the given id.
    • HasContainers As Boolean
    • HasPlacemarks As Boolean
    • HasProperties As Boolean
    • HasProperty (PropertyName As String) As Boolean
    • IsInitialized As Boolean
  • Properties:
    • ContainerId As String [read only]
      Gets the Container ID if it is specified.
    • Properties As Map [read only]
      Gets a Map where Map Keys are property names and Map Values are property values.
  • KmlPlacemark
    Methods:
    • GetId As String
    • GetProperty (Property As String) As String
    • HasGeometry As Boolean
    • HasProperties As Boolean
    • HasProperty (Property As String) As Boolean
    • IsInitialized As Boolean
  • Properties:
    • InlineStyle As KmlStyle [read only]
    • MarkerOptions As MarkerOptions [read only]
    • PolygonOptions As PolygonOptions [read only]
    • PolylineOptions As PolylineOptions [read only]
    • StyleId As String [read only]
  • KmlStyle
    Methods:
    • IsInitialized As Boolean
    • SetLineStringWidth (Width As Float)
      Sets the width of the LineString in screen pixels.
    • SetMarkerHotspot (X As Float, Y As Float, xUnits As String, yUnits As String)
      Sets the hotspot / anchor point of a marker.
    • SetMarkerRotation (Rotation As Float)
      Sets the rotation / heading of the Point in degrees clockwise about the marker's anchor.
    • SetPolygonFillColor (FillColor As Int)
    • SetPolygonStrokeWidth (StrokeWidth As Float)
      Sets the stroke width of the Polygon in screen pixels.
  • Properties:
    • Rotation As Float [read only]
      Gets the rotation of a marker in degrees clockwise about the marker's anchor.

A simple b4a project that loads a KML file from file assets - works for me though the web based infowindow content of the KML is a fail!

Code: Copy
#Region  Project Attributes
   #ApplicationLabel: Android Maps Utils
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
   '   GoogleMaps additional jar
   #AdditionalJar: com.google.android.gms:play-services-maps
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals

End Sub

Sub Globals
   Dim GoogleMap1 As GoogleMap
   Dim MapFragment1 As MapFragment
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Main")
  
   If Not(MapFragment1.IsGooglePlayServicesAvailable) Then
     Log("Google Play Services is not available")
     ToastMessageShow("Google Play Services is not available", False)
   End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub MapFragment1_Ready
   Log("MapFragment1_Ready")
   GoogleMap1=MapFragment1.GetMap
   If GoogleMap1.IsInitialized Then
     Dim CameraPosition1 As CameraPosition
     CameraPosition1.Initialize(52.7523, 0.4049, 10)
     GoogleMap1.AnimateCamera(CameraPosition1)
    
     Dim KMLLayer1 As KMLLayer
     KMLLayer1.Initialize(GoogleMap1, File.OpenInput(File.DirAssets, "75116131-1-KML0.simple.kml"))
     KMLLayer1.AddLayerToMap
    
     If KMLLayer1.HasContainers Then
       Dim Containers As List=KMLLayer1.GetContainers
       '   TODO
     End If
    
     If KMLLayer1.HasPlacemarks Then
       Dim Placemarks As List=KMLLayer1.GetPlacemarks
       '   TODO
     End If
    
   Else
     Log("Error initializing GoogleMap")
     ToastMessageShow("Error initializing GoogleMap", False)
   End If
End Sub

I'll attach this first version of my library, the simple demo project and a temporary updated version of GoogleMapsExtras for you all to have a look at.

I shall release a proper update to GoogleMapsExtras over the next week - if you want to try AndroidMapsUtils and use the MarkerOptions object then overwrite you current GoogleMapsExtras jar and xml files with the temporary ones.

@DonManfred
Thanks a lot, once i found the latest version of the play services jar i was able to get SLC to work.
Let's liase later in the week to turn this into a shared collaboration.

Martin.
Please Help me, I run your Example Demo but AndroidMapsUtils and KMLLayer error on my B4A10.7 and targetSdkVersion="30"
main$ResumableSub_Activity_Createresume (java line: 432)
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/LruCache;
at com.google.maps.android.data.Renderer.<init>(Renderer.java:115)
at com.google.maps.android.data.kml.KmlRenderer.<init>(KmlRenderer.java:46)
at com.google.maps.android.data.kml.KmlLayer.<init>(KmlLayer.java:44)
at uk.co.martinpearman.b4a.androidmapsutils.data.kml.KMLLayer.Initialize(KMLLayer.java:30)
at nta.kml.ge.main$ResumableSub_Activity_Create.resume(main.java:432)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:238)
at android.app.ActivityThread.main(ActivityThread.java:7798)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
Caused by: java.lang.ClassNotFoundException: android.support.v4.util.LruCache
... 15 more
main$ResumableSub_Activity_Createresume (java line: 432)
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/LruCache;
at com.google.maps.android.data.Renderer.<init>(Renderer.java:115)
at com.google.maps.android.data.kml.KmlRenderer.<init>(KmlRenderer.java:46)
 
This error means that the library needs to be jetified (Tools - Jetify libraries).
I tried running Tools - Jetifier (AndroidX) - Jetify libraries but it didn't fix the "Failed resolution of: Landroid/support/v4/util/LruCache; " error
Coud you please help me !
 
[QUOTE = "Erel, bài đăng: 831483, thành viên: 1"]
Bạn có thấy thư viện KML trong danh sách các thư viện sẽ bị hủy bỏ không? Lưu ý rằng các thư viện nội bộ sẽ không bị kiểm duyệt.
[/TRÍCH DẪN]
Thank Erel, Let me see
 
Did you see the KML library in the list of libraries that will be jetified? Note that internal libraries will not be jetified.
Yes, i see
1624202438186.png

1624203472794.png

I tried running Tools - Jetifier (AndroidX) - Jetify libraries but it didn't fix the "Failed resolution of: Landroid/support/v4/util/LruCache; " error
Coud you please help me !
 
Last edited:
Back
Top