I'm drawing a lot of markers on the map and when they located close they overlap each other. So I want to hide some markers on small zoom and show more markers when user zooming map. Like more zoom in, more markes. Here is example code of activity and creating of markers, as you can see I'm using google maps android api v2:
public class MainActivity extends FragmentActivity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.getUiSettings().setMyLocationButtonEnabled(true);
createMarkers(map);
}
private void createMarkers(GoogleMap map) {
double initLat = 48.462740;
double initLng = 35.039572;
for(float i = 0; i < 2; i+=0.2) {
LatLng pos = new LatLng(initLat + i,initLng);
map.addMarker(new MarkerOptions()
.position(pos)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
}
for(float i = 0; i < 2; i+=0.2) {
LatLng pos = new LatLng(initLat, initLng + i);
map.addMarker(new MarkerOptions()
.position(pos)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
}
}
It sounds like typical task for me, but i still didn't manage to find working solution. I've read this article https://developers.google.com/maps/articles/toomanymarkers but I've no idea how to implement it on android. Does anybody has some working code which can do this?