Android Question marker click with google maps

tufanv

Expert
Licensed User
Longtime User
Hello

I am using googlemaps lib ( not extras ) . I have a table which lists lats and longs of the 4 markers visible on the map. When I click on table , I want to show the snippet of a marker but i cant find how to manually trigger a marker click. For example when the user click on a table item i want to also execute a marker click ( without user click on the marker ) so that marker snippet will be visible . What must i use ?

TY
 

warwound

Expert
Licensed User
Longtime User
You need to keep a reference to each and every Marker when they are created.

B4X:
Dim MyMarkers As List
MyMarkers.Initialize

MyMarkers.Add(gmap.AddMarker(cursor1.GetString("lat"),cursor1.GetString("lon"),cursor1.GetString("runid")))

Or a Map:

B4X:
Dim MyMarkers As Map
MyMarkers.Initialize

MyMarkers.Put("A UNIQUE ID", gmap.AddMarker(cursor1.GetString("lat"),cursor1.GetString("lon"),cursor1.GetString("runid")))

Using a Map makes it easy to assign a string key identifier to each Marker.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
So when adding a actual marker will i use gmap.addmarker(mymarkers.get(i)) for exp ?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Yes.

AddMarker returns a reference to the newly created Marker.
You can keep the reference if required or discard it.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
sorry
when i use
gmap.addmarker(mymarkers.get(i))
it expects 3 values thats why gives error. ( it expects lat,lon,title) we give only 1 .
Yes.

AddMarker returns a reference to the newly created Marker.
You can keep the reference if required or discard it.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
gmap.addmarker(mymarkers.get(i))

Ooops i quickly read your last post and didn't notice you'd got the syntax wrong!

MyMarkers is a Map or List which you populate with the return value of the AddMarker method.
Use you previous code to call AddMarker and assign the return value of the AddMarker method to a variable:

B4X:
Dim MyMarker As Marker
MyMarker=gmap.AddMarker(cursor1.GetString("lat"),cursor1.GetString("lon"),cursor1.GetString("runid"))

MyMarker is now a reference to that new Marker.
Elsewhere in your code you can do:

B4X:
MyMarker.InfoWindowShown=True

Now you are creating a number of Markers - one for each row in a database query result i think?
So using a single variable to hold references to all your Markers is not possible of course.
You have to decide how to store all these Marker references - what will work best for your app:
  • A List of Markers.
    Will this work for you - will you know the Marker's index in that List so you can get the required reference to it?
  • A Map where the Map values are Markers.
    The Map keys can be unique indicators of any sort (string, integer etc).
    What is your database column 'runid'?
    cursor1.GetString("runid")
    is this a unique identifier you could use as the Marker's key in the Map?
    If so then a Map sounds like the best way for you to keep these Marker references.
  • An Array of Markers.
    Easy to implement if you know exactly how many Markers you need to create - and that number will not increase.
    Like a List, a numeric index in the array is required to get the Marker reference you need.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
B4X:
Dim MyMarkers As Map
MyMarkers.Initialize

'    now start looping through your database query rows
'    in every iteration of the loop do something like:
MyMarkers.Put(cursor1.GetString("runid"), gmap.AddMarker(cursor1.GetString("lat"), cursor1.GetString("lon"), cursor1.GetString("runid")))

'    once you've finishing looping through your database query rows you'll
'    have a Map whose keys are your 'runid' columns and whose values
'    are the Markers

As long as you know a Marker's 'runid' then you can get the Marker from the Map and set it's InfoWindowShown property.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User

Works exactly as i wanted. TY again !
 
Upvote 0

Daniel-White

Active Member
Licensed User
Longtime User
Hi guys. I can't find the sintaxis to enable the infowindow for each mark. using that code , I am trying to show in the map all the marks from database and show the infowindows with the value of x

with one mark I can use this "Marker1.InfoWindowShown" and work, but how with the MyMarkers map.?
Thanks


B4X:
For  x =1 To 100   
           Cursor1 = SQL1.ExecQuery("SELECT * FROM Example WHERE ID = " & x)   
        Cursor1.Position = 0                                    'set the cursor
        Log ("show entry "& Cursor1.GetString("Latitud"))
        Log ("show entry "& Cursor1.GetString("Longitud"))
        Log ("Show entry  supuesto ID ="&x)
       

        'Marker1 = GoogleMap1.addmarker2(Cursor1.GetString("Latitud"),Cursor1.GetString("Longitud") , x,GoogleMap1.HUE_YELLOW)
        MyMarkers.Put(x, GoogleMap1.addmarker2(Cursor1.GetString("Latitud"),Cursor1.GetString("Longitud") , x,GoogleMap1.HUE_YELLOW))

Next
 
Upvote 0

Daniel-White

Active Member
Licensed User
Longtime User
It would have been better to start a new thread for this question.

B4X:
Dim m As Marker = MyMarkers.Get(5)
m.InfoWindowShown = True

Thanks you Erel, that help me a lot, I am not 100% sure, but the method of google map only allow me to show the last InfoWindowShown, the last Mark draw over the google map.

, I think we can put all the InfoWindowsShow, because in http://maps.google.com has that feature. But with you reply, I changed my mind, and I did something more easy with you example code and the code of WarWound.

I can show the InfowindowShown step by step, I mean, show in the GoogleMap the tracer route step by step and show one by one the Markers with the InfoWindowsShown that is enough and work for me too. indeed is better for the End user follow the routes, than show all the Infowindowsshown in only one click.
As usual, Thanks you Indeed.
Daniel White
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
I have followed the above code. I now have a map named MyMarkers and the the markers are displayed on the GoogleMaps.
Now how do I capture the click event of the Marker ?
I am not using GoogleMapsExtra, just the regular GoogleMaps

I have a label displayed just below the GoogleMap, I need to change the label's content based on the Marker clicked by the user

Does the Marker's have a click event ?
How do I know which Marker was clicked ? Can I keep any information tags on each Marker created, so thqt I can use that tag to pull information from the database to display information on the labels ?

Any help will be appreciated.

Regards
Anser
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…