#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