HOW TO REMOVE COMPLETELY MARKERS FROM A MAP

2,353 views
Skip to first unread message

Carlo Orsini

unread,
Mar 22, 2018, 7:59:42 AM3/22/18
to MIT App Inventor Forum
Dear all,

How can I remove with the app all the markers placed previously on a map? I mean to remove them physically from the memory (not setting visible to false).

Thank you 

Carlo 

SteveJG

unread,
Mar 22, 2018, 9:13:08 AM3/22/18
to MIT App Inventor Forum
If you set the Markers at design time, you probably cannot remove them.   If you set the Markers at run time, think about how that is done.  That might be the clue.  Yes, you create a List of runtime objects.

Perhaps
Features
Sets or gets a list of features present on the Map. Setting this to an empty list will clear the Map.

is useful?   I don't know.   See also

Type
Gets the type of the feature. For Marker, this will always be "Marker",

Seems to me that since a Marker is a Feature, Setting the Feature to an empty list might work.


Homework:
1) Please turn off your Caps Lock on your keyboard
2) Experiment and let us know if the above works; perhaps provide an example?   

Thanks Carlo.

Regards,
Steve



Carlo Orsini

unread,
Mar 22, 2018, 11:08:53 AM3/22/18
to MIT App Inventor Forum
Great Steve, as a matter of fact "Set Map1.Features" to "create empty list" clean completely the map! 

Unfortunately I didn't find out how to get the type of the feature (as you write above). Map1 feature should be a list of features. How can I get the type of each item?

The idea was to cancel all the markers from listamarkers but to maintain the main Marker1 connected to locationsensor. Of course emptying the whole Map1 feature list cancel also the main marker1.

Any idea?

Carlo


SteveJG

unread,
Mar 22, 2018, 11:48:59 AM3/22/18
to MIT App Inventor Forum
Glad that suggestion worked.  It had unintended consequences.

Perhaps you can use Features
Returns a list of features present in the feature collection, if any.
?
and use the information to  not to completely empty the Map1.Features list but selectively delete using a loop to delete only the run time features.   Something like    if select list item list/index not Marker1  (the green puzzle piece that is the lowest Marker puzzle piece)  remove list item list / index .  Of course, cycling through the list will be slower than clearing the list, depending on how many Markers you are eliminating.

That Marker1 (assuming it is a design time object) is also cleared is a surprise but not entirely unexpected.  That response appears to either be a bug or an intentional response that might be part of the Java osmdroid-library the map control uses to interface with OpenStreetMap. I expect it is intentional, so instead of emptying the List, selectively delete blocks.


If Users want to do what you want to do with the MIT Map Marker, they might have to reinstate Marker1 or or other design time features as a run time Marker following emptying the Features list.  Something like  call Map1.CreateMarker latitude  LocationSensor.Latitude  
                                                            longitude  LocationSensor.Longitude       and note it's real time name.

A way around this is not to use a Marker for your current geolocation but instead, in the Map component     set ShowUser to  true and a different icon will display at your current location.  I expect emptying Features will not mess with that icon.  See 
 ShowUser
Shows or hides an icon indicating the user's current location on the Map. The availability and accuracy of this feature will depend on whether the user has location services enabled and which location providers are available.



Regards,
Steve

Carlo Orsini

unread,
Mar 22, 2018, 12:11:29 PM3/22/18
to MIT App Inventor Forum
Thank you Steve, I can't use call Map1.CreatMarker because it leaves many markers on the map and I want the marker only in my current position.

The best thing would be to use ShowUser but actually it gives to me a not nice icon. Do you know how to change or set this marker image?

In the meantime I try if showuser marker is deleted or not.

Thank you

Carlo

Carlo Orsini

unread,
Mar 22, 2018, 12:18:55 PM3/22/18
to MIT App Inventor Forum
Steve,

ShowUser marker would be perfect, emptying the Map1 features list doesn't cancel that marker.

                            

My smartphone give me as a showuser marker a little man yellow, not suitable for me. In the designer instead it shows a nice blue marker I would like ↑ .

How to change the icon ?

SteveJG

unread,
Mar 22, 2018, 12:38:02 PM3/22/18
to MIT App Inventor Forum
The ShowUser changes supposedly automatically depending on what is happening with the device.  If in a vehicle, the yellow man is replaced.  I do not think the developer has control of what icon is displayed.   Drive around the block, get lunch and see what happens?

With Android Studio you could do this  https://stackoverflow.com/questions/47093133/osm-show-current-location-with-custom-icon    but with AI2 you get the default response.  Map objects depends entirely on the osmdroid library to interface to OpenStreetMaps and it is evident AI2 does not have the capability of defining a custom icom.

Time to graduate to Android Studio?

But first, take a drive and see what happens to the showuser icon.

Evan Patton

unread,
Mar 22, 2018, 3:44:02 PM3/22/18
to MIT App Inventor Forum
Hi Carlo,

Once you create the marker for the user, why not just update the latitude and longitude using a LocationSensor? This would give you the benefit of a custom image asset for the marker and not require making more than one.

Evan

Carlo Orsini

unread,
Mar 22, 2018, 5:14:47 PM3/22/18
to MIT App Inventor Forum
Hi Evan, if I understand right your advice, this what I did but then it's not easy to cancel all other markers except the user one.

Carlo

Evan Patton

unread,
Mar 23, 2018, 3:50:27 PM3/23/18
to MIT App Inventor Forum
Hi Carlos,

If you stash the reference to the user marker in a variable, then you could reinitialize the the features property with a list containing just the user marker.

Evan

TimAI2

unread,
Mar 25, 2018, 10:56:40 AM3/25/18
to MIT App Inventor Forum
Been having a little play with this (working something up with "map" myself!)
Blocks show creation of new markers at run time using a long press on point
Also removal of all markers except the first one in the list (which is the "home" marker created at design time)
Found it is possible to set the title and change other characteristics of the remaining first marker
The for each routine wouldn't work directly with the Map1.features block as a list but putting it into a variable list worked


Carlo Orsini

unread,
Mar 26, 2018, 5:56:11 AM3/26/18
to MIT App Inventor Forum
Great solution !

I have the Marker1 that follow my positon and use one type of image asset and this one should not be cancelled, the other markers use a different image asset and they can be cancelled. This system works. Thank you so much. Hereby attached my test.


Reply all
Reply to author
Forward
0 new messages