Wish Googlemaps update - cluster marker

salvadoro

Member
Licensed User
Longtime User
I would like to have the marker cluster functionality, also this library has not been updated for many years, some updates were made such as Googlemaps_extra, there will be an update date, or someone in the forum who has made a more updated wrapper that sells it, to be able to develop applications with map management that compete with native developments.
 

DonManfred

Expert
Licensed User
Longtime User
MarkerCluster is not a GoogleMaps-functionality.
It is a thirdparty project ehich extends the functionality.
You´ll have to implement this thirdparty project i guess.
 

salvadoro

Member
Licensed User
Longtime User
Can someone guide me on how to link the mapfragment with the clusters because it tells me that it is not in the library, which is obvious but I don't know how it can be linked, I already have the library and I am trying to add it with the javaobject from the Google API documentation says and I can't extend the functionality
 

salvadoro

Member
Licensed User
Longtime User
I get error with this code

B4X:
#AdditionalJar: android-maps-utils-3.8.2

Sub Process_Globals
    Private rp As RuntimePermissions
End Sub

Sub Globals
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
    Private joMap As JavaObject
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

Sub MapFragment1_Ready
    AddClusterManager
End Sub

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

Sub AddClusterManager
    joMap = gmap
    Dim context As JavaObject
    context.InitializeContext
    Dim clusterManager As JavaObject
    clusterManager.InitializeNewInstance("com.google.maps.android.clustering.ClusterManager", Array(context, joMap))

    ' Add items to the cluster manager
    Dim items As List
    items.Initialize
    items.Add(CreateClusterItem(37.7749, -122.4194)) ' Example item (latitude, longitude)
    For Each item As JavaObject In items
        clusterManager.RunMethod("addItem", Array(item))
    Next

    ' Set the cluster manager as the OnCameraIdleListener and OnMarkerClickListener
    joMap.RunMethod("setOnCameraIdleListener", Array(clusterManager))
    joMap.RunMethod("setOnMarkerClickListener", Array(clusterManager))
End Sub

Sub CreateClusterItem(Latitude As Double, Longitude As Double) As JavaObject
    Dim clusterItem As JavaObject
    clusterItem.InitializeNewInstance("com.google.maps.android.clustering.ClusterItem", Null)
    Dim LatLng As JavaObject
    LatLng.InitializeNewInstance("com.google.android.gms.maps.model.LatLng", Array(Latitude, Longitude))
    clusterItem.RunMethod("setPosition", Array(LatLng))
    Return clusterItem
End Sub

I get this error

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
Error occurred on line: 71 (Main)
java.lang.ClassNotFoundException: com.google.maps$android$clustering$ClusterManager
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
    at b4a.identity.main._addclustermanager(main.java:518)
    at b4a.identity.main._mapfragment1_click(main.java:659)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.MapFragmentWrapper$1$2.onMapClick(MapFragmentWrapper.java:145)
    at com.google.android.gms.maps.zzy.zzb(com.google.android.gms:play-services-maps@@18.1.0:1)
    at com.google.android.gms.maps.internal.zzal.zza(com.google.android.gms:play-services-maps@@18.1.0:3)
    at com.google.android.gms.internal.maps.zzb.onTransact(com.google.android.gms:play-services-maps@@18.1.0:3)
    at android.os.Binder.transact(Binder.java:921)
    at m.bcv.c(:com.google.android.gms.policy_maps_core_dynamite@241610205@241610202042.636179997.636179997:8)
    at com.google.android.gms.maps.internal.am.e(:com.google.android.gms.policy_maps_core_dynamite@241610205@241610202042.636179997.636179997:9)
    at com.google.maps.api.android.lib6.phoenix.ag.c(:com.google.android.gms.policy_maps_core_dynamite@241610205@241610202042.636179997.636179997:25)
    at m.dqq.run(:com.google.android.gms.policy_maps_core_dynamite@241610205@241610202042.636179997.636179997:5)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
    at m.cab.run(:com.google.android.gms.policy_maps_core_dynamite@241610205@241610202042.636179997.636179997:12)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8668)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)
 

TILogistic

Expert
Licensed User
Longtime User
B4X:
    items.Initialize
    items.Add(CreateClusterItem(37.7749, -122.4194)) ' Example item (latitude, longitude)
    For Each item As JavaObject In items
        clusterManager.RunMethod("addItem", Array(item))
    Next

you must create markers and add them to the cluster

check this routine it should return markers with their positions...etc
B4X:
Sub CreateClusterItem(Latitude As Double, Longitude As Double) As JavaObject
    Dim clusterItem As JavaObject
    clusterItem.InitializeNewInstance("com.google.maps.android.clustering.ClusterItem", Null)
    Dim LatLng As JavaObject
    LatLng.InitializeNewInstance("com.google.android.gms.maps.model.LatLng", Array(Latitude, Longitude))
    clusterItem.RunMethod("setPosition", Array(LatLng))
    Return clusterItem
End Sub
 

TILogistic

Expert
Licensed User
Longtime User
B4X:
        ' Add the marker to the ClusterManager for clustering
        ClusterManager1.RunMethod("addItem", Array(Marker1))
 

salvadoro

Member
Licensed User
Longtime User
hi @TILogistic now that I begin with CreateClusterItem get a error java.lang.ClassNotFoundException: com.google.maps$android$clustering$ClusterItem

Could you help me with the right way to have googlemaps internal library and #AdditionalJar: android-maps-utils-3.8.2

Cause I think that I need to do something else, this errors are cause don't find this classes
 

salvadoro

Member
Licensed User
Longtime User
Hi I have made progress and I no longer have errors with the initialization of the clustermanager.

B4X:
Sub CreateClusterManager As JavaObject
    Log("CreateClusterManager")
    joMap = gmap

    ' Move map to the position and zoom required
    Dim cp As CameraPosition
    cp.Initialize(19.0605903,-98.2979058, 8)
    gmap.MoveCamera(cp)

    ' Initialize clustermanager
    clusterManager.InitializeNewInstance("com.google.maps.android.clustering.ClusterManager", Array(GetContext, joMap))

    ' Asociate clustermanager with the map
    joMap.RunMethod("setOnCameraIdleListener", Array(clusterManager))
    joMap.RunMethod("setOnMarkerClickListener", Array(clusterManager))
    joMap.RunMethod("setOnInfoWindowClickListener", Array(clusterManager))

    'Create 10 markers
    Dim offset As Double
    Dim lat As Double = 19.0605903
    Dim lon As Double = -98.2979058
    For i = 1 To 10
        offset = i/60
        lat = lat + offset
        lon = lon + offset
        Dim Marker1 As Marker
        Marker1 = gmap.AddMarker(lat,lon,"Marker "& i)
        Dim item As JavaObject = Marker1
        clusterManager.RunMethod("addItem", Array(item))
    Next
    
    clusterManager.RunMethod("cluster",Null)

    Return clusterManager
End Sub

But now I have the next error could someone point me to the right way to add this marker to the cluster?


B4X:
Registro conectado a:  samsung SM-A546E
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
CreateClusterManager
Error occurred on line: 133 (Main)
java.lang.RuntimeException: Method: addItem not matched.
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
    at b4a.identity.main._createclustermanager(main.java:565)
    at b4a.identity.main$ResumableSub_Activity_Create.resume(main.java:465)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
    at anywheresoftware.b4a.BA$2.run(BA.java:395)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:230)
    at android.os.Looper.loop(Looper.java:319)
    at android.app.ActivityThread.main(ActivityThread.java:8919)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
 

DonManfred

Expert
Licensed User
Longtime User
But now I have the next error could someone point me to the right way to add this marker to the cluster?
You should start a new thread for any new question/issue.
Posting another question to the same thread is a mistake.

Away from that you are posting in the wrong section. This is the wish-forum. Only wishes should be posted here.

Post all your questions in the B4A Questionsforum.
 

TILogistic

Expert
Licensed User
Longtime User
I suggest you create a new post to create a class that allows all those interested to cooperate in the development of extended utility methods for Google Maps for Android.
I have developed several subroutines that I have published on the forum that could be incorporated into this class.


Regarding your error, use your subroutine that I mentioned that you will review.

I see several interested Spanish and Portuguese speakers.
 
Top