Android Question GoogleMaps Markers InfoWindow

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to all.
my problem is to understand well the behavious of Markers (and polylines) added to a GoogleMaps map. What seems to me, is that, after adding, for example, a marker to the GoogleMaps Map, there is no way to retrieve it from the map and modify its properties. My problem is to hide the InfoWindow after having created the Markers. For example, I have map named Punti, containing objects to create the markers. The following code, which seemed me correct, doesn't work:

B4X:
                   Dim gmap as GoogleMaps
                   Dim Punti as Map
                   Dim M as Marker
                   ... code to populate the Punti with data
                   For i=0 To Punti.Size-1
                   Pun=Punti.GetValueAt(i) ' Pun is an Object with Name,Latitude,Longitude
                   M= gmap.AddMarker3(Pun.Latitude, Pun.Longitude, Pun.Name)
                   M.InfoWindowShown=False 
                Next

Also this variant, based on another post on this subject, doesn't work:

B4X:
                   Dim gmap as GoogleMaps
                   Dim Punti as Map
                   Dim Markers as List
                   ... code to populate the Punti with data
                   Markers.Initialize
                   For i=0 To Punti.Size-1
                      Pun=Punti.GetValueAt(i) ' Pun is an Object with Name,Latitude,Longitude
                      Markers.Add(gmap.AddMarker3(Pun.Latitude, Pun.Longitude, Pun.Name))
                    Next
                    ForEach m as Marker in Markers
                         m.InfoWindowShown=False
                    next

Does anybody have any hint?
Thanks in advance
 

DonManfred

Expert
Licensed User
Longtime User
Does anybody have any hint?
you are not using a Map correctly. I would start fixing this first.

See Point 3
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
you are not using a Map correctly. I would start fixing this first.

See Point 3
Sorry : which Map ? If you mean the Punti Map, probably I wrote the code here not well. I successfully create the markers in the GoogleMap gmap, with the function AddMarker3. The problem is to retrieve the marker after inserting it. Let's focus on second variant. Probably I cannot add the object created by the AddMarker3 to the Markers List, in the way I did? WHich is then the correct way? I don't understand the "point 3" of your suggestion.. unluckily..
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Basically my deduction is: the objects added to GoogleMaps gmap are not accessible. If I want to modify them, I must remove them from the gMap and recreate. In my example, first I must gMap.clear, and then use addMarker, not AddMarker3, if I don't the InfoWindow.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Basically my deduction is: the objects added to GoogleMaps gmap are not accessible. If I want to modify them, I must remove them from the gMap and recreate. In my example, first I must gMap.clear, and then use addMarker, not AddMarker3, if I don't the InfoWindow.
You do NOT have to remove Google objects. all googlemaps objects have an identifier, whose properties can be modified.
example:
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
You do NOT have to remove Google objects. all googlemaps objects have an identifier, whose properties can be modified.
example:
Thanks. But your indication describes a mark which was "clicked" by the user. My question is another: how to access the Markers that were inserted in the map? GoogleMaps object "gmap", has no function to access the markers. As you can imagine, if I have 1000 markers, and want to change all of them, I cannot click on each one of them... In another post, Erel said to store the markers in a List, and then process the markers properties with a loop on the list. But this seems not to work. The process I use is simple:
1) Create the Marker with AddMarker3
2) Store the Marker object created by the AddMarer3 in a List
3) Process each Marker stored in the List.
But this seems to have no influence on the displayed GoogleMaps gmap. This is why I deduct that the Markers, once inserted in the gmap, are not accessible, andcan only be eliminated and re-created. In my case, of course. Your example is different.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
@GiovanniPolese I think you understanding the Marker Creation... but you must understand how the GoogleMap working...

I suggest you check my example-project (B4A - B4J) here - if you have time:

* Marker can be an array (of markers)
* a List is something for helping you (at my example using one)

Check if you want... may be will help you understand it...
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
check at the example, the following subs:
B4X:
ShowMarkerFromList(uid As String)
...
MarkerAddtoList(uid As String,lat As Double,lng As Double)

uid... is the uniqueid you want..
I will check your example, but "how googlemaps works" seems clear: no function to retrieve the objects from the GoogleMaps map and modify them, like I was (naively, but not too much, sorry) expecting. After this, if I added 1000 markers, let's suppose that one of the markers has to be changed. Shall I click on it, as the only option to access it? Yes or not. Clearly Yes, but it seems the only way. For example, let's suppose that I want display the markers, without the InfoWindow, while they were created with the InfoWindow. So, to change 1000 markers, I must click 1000 times.. This is the reason why i thought that the way depicted by Erel in that old post, was effective. (Probably it is, but I miss something, then). As I said, it was not me to "invent" the story of the List to store the markers, but Erel, (which normally only writes right things here) . Moreover the user making the question "how to change the markers properties", answered "thank you.. everything is working". This confuses me, because any action done on the markers, after have added them to the googlemaps map, seems not possible. Therefore I guess that:
1) I must add the Markers
2) Store the entity generating each marker in a List or Array
2) If any change (not clicking on them) on a marker, due to programmatical needs, clear all the markers and add them again, using the List (or Array..) with modified properties.
Sorry. I was not thinking that it was so difficult to explain. Forgive me.. Thanks again
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
100% wrong! gmap.AddMarker3 returns the marker which you can store in a map or list for later references.
Use the object from the map/list to change a marker if needed.
Hi. So, why the second variant of my first post is not working? What I miss? Or, maybe, some other explanation..
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Upload a working app so we could test it (you can remove your api-key though)

Really hard to help with the small code-snippet, wrong use of a map, ect.
I understand, but it is not so practical to upload the code. Things are really simple, as I posted at first. Second variant of my first post must work, you say (and also ancient Erel post says the same), So there is little to discuss. I will try to find my error. If not, I will be back with a complete test project. Thanks.
 
Upvote 0
Top