Android Question GoogleMap Marker Click event

Anser

Well-Known Member
Licensed User
Longtime User
Hi

On one of the activities in my app, the screen is split horizontally into 2 portions ie on the top portion, I have Google Maps and the bottom portion I have few labels.

On the Google Maps I have placed around 20 to 25 markers. The markers are placed on the Google Maps based on the latitude & longitude data picked from the remote database. When the user clicks on a marker, I need to pick more details regarding the clicked marker from my database and display it on the labels placed below the Google Maps.

I need to identify the marker clicked, so that I can pick more information about the Marker from the database.

I have used the regular Google Maps and NOT the GoogleMapsExtra

Any help will be appreciated.

Regards
Anser
 

DonManfred

Expert
Licensed User
Longtime User
From the GoogleMaps xml

MarkerClick (SelectedMarker As Marker)

I guess you should use this event to get the marker...
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
you will have to put your markes to a map (the collection structure, not google map), something like:
B4X:
'define your map in sub globels
Private Markers1 As Map
'...later anywhere in your code create a marker and put it to the map as key   
Dim aMarker As Marker = GoogleMap1.AddMarker(lat1,lon1,"myTitle")
Markers1.Put(aMarker, "somevalues..or object.")

'later when you need the marker again and connect it to your information
aObject = Markers1.get(aMarker)
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
eurojam,
I have used Maps collection as you sugested and all the marker details are available in the Maps collection. How do I know which marker was clicked by the user ?

Regards
Anser
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
you can do it like Erel described, but then you will have this balloon-stuff on your map....if you don't want a balloon but something else like a panel filled with information about the marker you will have to do something with googlemapsextras. First definening an InfoWindowAdapter in the Sub MapFragment1_Ready:
B4X:
...
Dim InfoWindowAdapter1 As InfoWindowAdapter
InfoWindowAdapter1.Initialize("InfoWindowAdapter1")
GoogleMapsExtras1.SetInfoWindowAdapter(GoogleMap1, InfoWindowAdapter1)
...
and later
B4X:
Sub InfoWindowAdapter1_GetInfoWindow(Marker1 As Marker) As View
' the default InfoWindow will be used if this event Sub is not defined or if it returns Null
'do something with your marker
aObject = Markers1.get(Marker1)
...
'and show a transparent label on the map instead of the balloon
   Dim InfoWindowLabel As Label
   InfoWindowLabel.Initialize("")
   InfoWindowLabel.Color=Colors.Transparent
   InfoWindowLabel.TextColor=Colors.Transparent
   Return InfoWindowLabel
End Sub
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
i already answered this in post #2 which is liked by anser. But he does not make use of the info it seems :-(
I was wondering how to implement the click event as initially I could not find any event associated with the MapFragment.;)
I was dump and didn't think about the option available in the designer to check the events associated with the MapFragment. It was available via the designer's menu Tools->Generate Members. :)

Sometime our brains doesn't work. :)
Finally discovered
Sub MapFragment_MarkerClick


Actually with my question to eurojam "How do I know which marker was clicked by the user ?" was to understand how to track the clicked marker. I mean, we don't have the TAG property in Marker to store additional information for eg Record_ID. Now I have used the Marker.Snippet, not an elegant solution. For the time being its serving the purpose.
 
Last edited:
Upvote 0
Top