I am developing a location-based Android application that deals with many overlay elements.
Background: There are quite a few objects that I want to display on the map. The coordinates of objects change in real time as their location changes. In accordance with the updated location, objects must be updated on the map. Entities can grow to a large number.
Implementation I have two overlays. One for MyLocationOverlay to display the user's location, and the other a subclass of ItemizedOverlay with all the objects that I need to display on the map.
Problem Whenever the location of an object changes, the corresponding overlayitem must be updated. The problem is that I'm not sure if this is the best way to achieve this. I have these options
When I get the location of a specific object, I delete all overlays from the map and re-add overlays. One of the overlayitems is now created with an updated location.
List<Overlay> overlays = map.getOverlays(); overlays.removeAll(overlays); overlays.add(new MyOverlay(marker,this));
I create an Overlay for each object. Value I will create 500 overlays, each containing only one overlay element. I create a subclass of the Overlay class and add my own properties to clearly identify the entity and create it for everyone. When I achieve an update in the location of a specific object, I repeat and get a specific overlay element, delete it and add a new one with an updated location.
I do not know which one is the best to use.
I feel that deleting all and re-adding all overlays for each location update (which can be quite common) of each individual object becomes quite expensive when the number of objects becomes more than 500 or 1000.
At the same time, iterating through the same number of objects can be the same invoice.
Any advice on which to choose one or the best way to implement this will be appreciated.
/Andy
source share