简体   繁体   中英

Clever way of removing and re-adding single existing markers in google maps API v2 Android

I've built an Android application that uses google maps Api v2. the application listens for data and then places the marker when data is received. The data is made up of an ID, lat and lon.
I would like to be able to look at the ID, check to see if a marker with that ID exists, if it does then I would like to clear that marker from the map and add a new marker with that ID and place it at the updated lat lon coords.

Does anyone have any ideas on what would be the best way to do this?

When you create the marker you need to store it in a way that can be identified by however you are differentiating markers. One simple way would to create an array of Markers and store every new marker in the said array. You can loop through the array and check each marker for a unique attribute (id, position, or maybe something you've added to the title/snippet). Then you can remove the appropriate marker and create it in the new position with new properties or simply change the position of the marker with setPosition .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM