Google map clustering is not working for small count of cordinates

Viewed 33

I am using the Google Map Clustering demo application example to play with it. As per in the example offset are following:

private void readItems() throws JSONException {
    InputStream inputStream = getResources().openRawResource(R.raw.radar_search);
    List<MyItem> items = new MyItemReader().read(inputStream);
    for (int i = 0; i < 5; i++) {
        double offset = i / 60d;
        for (MyItem item : items) {
            LatLng position = item.getPosition();
            double lat = position.latitude + offset;
            double lng = position.longitude + offset;
            MyItem offsetItem = new MyItem(lat, lng);
            mClusterManager.addItem(offsetItem);
        }
    }
}

Clustering is working perfectly for large numbers of coordinates (=>5). To understand let's take two scenarios:

  • First scenario I am loading two coordinates through following data file:

    [
     { "lat" : 28.5092163, "lng" : 77.4135367 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5092163, "lng" : 77.4135367 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5092163, "lng" : 77.4135367 },
     { "lat" : 28.5092163, "lng" : 77.4135367 },
     { "lat" : 28.5092163, "lng" : 77.4135367 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 }
    ]
    

    As we can see in above data file that count of { "lat" : 28.5102148, "lng" : 77.411671 } is 9 and count of { "lat" : 28.5092163, "lng" : 77.4135367 }, is 5. Screenshot of the emulator:

enter image description here

  • Second scenario I am loading two coordinates through following data file:

    [
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5092163, "lng" : 77.4135367 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5092163, "lng" : 77.4135367 },
     { "lat" : 28.5092163, "lng" : 77.4135367 },
     { "lat" : 28.5092163, "lng" : 77.4135367 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 },
     { "lat" : 28.5102148, "lng" : 77.411671 }
    ]
    

    As we can see in above data file that count of { "lat" : 28.5102148, "lng" : 77.411671 } is 9 and count of { "lat" : 28.5092163, "lng" : 77.4135367 }, is 4. Screenshot of the emulator:

enter image description here

So, the problem is whenever I am passing less than 5 coordinators for the same Lat,Lng. Google map wont's showing the cluster. It supposed to be show as 9 and 4.

I tried to follow the documentation but nothing is heling me out. What am I doing wrong here?

Thanks for your help.

1 Answers
Related