I've tried to implement the cluster manager following this Google Developers toutorial but my markers are displaying extremely inaccurately compared to just using googleMap.addMarker();
(example).
Here is an image comparison of the two
I suppose it has to do with the offset
in the addClusterPoints()
but when I change the divisor(60d
), the only change is how far the points are spread out but still an incorrect location. I've tried changing the value of 60d
and I've found that with <60d
they are more spread out and >60d
They are less spread out.
Could someone explain what the offset
is doing and how to get the points to display accurately?
private void addClusterPoints(){
List<LatLng> locations= new ArrayList<>(getLatLongList());
for(int i=0; i < locations.size(); i++){
double offset = i /60d;
latLng = locations.get(i);
double lat = latLng.latitude + offset;
double lng = latLng.longitude + offset;
mapClusterItem offsetItem = new mapClusterItem(lat, lng, "Tile "+i, "Snippet"+i);
clusterManager.addItem(offsetItem);
}
}
As Andy commented, the issue was in the offset
. I've removed the offset
and the markers are displaying at their expected locations.
The Google Developers tutorial I referenced has the offset
so I thought it was part of the process but it turns out it's completely unrelated. I honestly find it strange that they would decide to include that in the tutorial. The only reasoning I could think of why they would do that (since they don't provide one) would be to create some space between items that are very close together.