The way that Erel created the b4a GoogleMaps library did not expose the
MarkerOptions object and this is the object you'd need to use to create a Marker that is initially not visible.
So i've now partly wrapped the MarkerOptions object and added a new method to GoogleMapsExtras
AddMarker(MarkerOptions1 As MarkerOptions) As Marker.
Have a look at this example code:
Sub Process_Globals
End Sub
Sub Globals
Dim MapFragment1 As MapFragment
Dim GoogleMap1 As GoogleMap
Dim GoogleMapsExtras1 As GoogleMapsExtras
Dim MapPanel As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
If MapFragment1.IsGooglePlayServicesAvailable = False Then
ToastMessageShow("Google Play services not available.", True)
Else
MapFragment1.Initialize("MapFragment1", MapPanel)
End If
End Sub
Sub MapFragment1_Ready
Log("MapFragment1_Ready")
GoogleMap1 = MapFragment1.GetMap
If GoogleMap1.IsInitialized = False Then
ToastMessageShow("Error initializing map.", True)
Else
' use the new MarkerOptions method to create and add a Marker to the map
Dim MarkerOptions1 As MarkerOptions
MarkerOptions1.Initialize
MarkerOptions1.Position2(52.75619, 0.3980).Snippet("Home is where the heart is").Title("Home Sweet Home").Visible(True)
Dim Marker1 As Marker=GoogleMapsExtras1.AddMarker(GoogleMap1, MarkerOptions1)
Dim CameraPosition1 As CameraPosition
CameraPosition1.Initialize(52.75619, 0.3980, 6)
GoogleMap1.AnimateCamera(CameraPosition1)
End If
End Sub
MarkerOptions
Methods:
- Anchor (U As Float, V As Float) As MarkerOptions
- Draggable (Draggable As Boolean) As MarkerOptions
- Initialize
- IsInitialized As Boolean
- Position (LatLng1 As LatLng) As MarkerOptions
- Position2 (Latitude As Double, Longitude As Double) As MarkerOptions
- Snippet (Snippet As String) As MarkerOptions
- Title (Title As String) As MarkerOptions
- Visible (Visible As Boolean) As MarkerOptions
I've not fully wrapped the MarkerOptions object, there are various other methods that can also be wrapped, take a look:
https://developers.google.com/maps/...m/google/android/gms/maps/model/MarkerOptions.
Code and beta library files attached - i'll complete the MarkerOptions object hopefully tomorrow and get it uploaded to the GoogleMapsExtras thread.
When the device orientation changes you have no way to tell the activity not to destroy all of it's objects and variables - that's the way android works.
You could keep references as process global objects - not sure about a sticky service but i guess that's another way to keep a reference to objects you create but don't want destroyed when the orientation changes.
Note that you should not keep a reference to a Marker - a Marker is an Activity object and should be destroyed when the activity is destroyed.
Don't try to keep a process global reference to a Marker - there's no point, you can't add a Marker to the map, BUT you can keep a process global reference to a MarkerOptions object.
So create a MarkerOptions object for each of your many markers, and keep each MarkerOptions object as a process global (or try and use a service), then on orientation change you can re-create new Markers from the (already created) MarkerOptions objects.
Martin.