I have a mapview in my application. And I have to show more than 1,000 overlays on a map. And I have a list which is containing these places. So, do I have to create 1,000 overlay objects by iterating over the items in the list? And can anyone give me an efficient way to do this?
Asked
Active
Viewed 973 times
1
-
see this link:http://stackoverflow.com/questions/4994800/displaying-multiple-markers-on-google-map – Lokesh Nov 02 '12 at 05:20
-
Possible [duplicated](http://stackoverflow.com/q/12483065/1050058). Check my answer for `Map Clustering` – Trung Nguyen Nov 02 '12 at 09:06
3 Answers
0
for this you don't have to make 1000 overlay.. just add overlay in itemizedoverlay and add this itemizedoverlay in mapoverlay and populate overlay before adding new itemizedoverlay..
try
{
point = new GeoPoint((int) (Double.parseDouble(list.get(i).getLatitude()) * 1e6),(int) (Double.parseDouble(list.get(i).getLongitude()) * 1e6));
overlayitem = new OverlayItem(point, list.get(i).getLocationName()+"_@_"+list.get(i).getLatitude()+"_@_"+list.get(i).getLongitude()+"_@_yes", list.get(i).getAddress());
itemizedoverlay.addOverlay(overlayitem);
itemizedoverlay.populateOverlay();
mapOverlays.add(itemizedoverlay);
}
catch (Exception e)
{
Log.v("log",""+e.toString());
e.printStackTrace();
}

Sanket Kachhela
- 10,861
- 8
- 50
- 75
0
The way the Sanket is doing it the points are populated after every single point is added, this tends to lag out. A more effiecent way can be done like this:
What is happening is that you are populating the MapView everytime you add a GeoPoint. Try adding this to your code:
after you have looped through the GeoPoints place this code
itemizedOverlay.populateNow();
and change you itemizedOverlay to look like this:
public void addOverlay(OverlayItem overlay) {
m_overlays.add(overlay);
}
public void populateNow()
{
populate();
}
@Override
protected OverlayItem createItem(int i) {
return m_overlays.get(i);
}
@Override
public int size() {
return m_overlays.size();
}

SquiresSquire
- 2,404
- 4
- 23
- 39
-
Hello. i am iterating the list in anther thread. now where to call the populateNow method on itemizedOveray – Sandeep Dhull Nov 02 '12 at 09:58
0
You can show only visible area markers and invisible area markers hide by below code;
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
for (Marker marker : markerArrayList) {
if (bounds.contains(marker.getPosition())) {
marker.setVisible(true);
} else {
marker.setVisible(false);
}
}
}
});

Vishal Vaishnav
- 3,346
- 3
- 26
- 57