Android-maps-utils: Cluster with markers in same location take default design

Created on 10 Mar 2020  路  12Comments  路  Source: googlemaps/android-maps-utils

Hello,

I've update the library from 0.6.2 to 1.0.0 and I have a trouble with Cluster (Bug is not present in version 0.6.2)
I have Custom Cluster
When I have markers in same location, the Cluster take the default design and not mine

Screenshot_1583853766
Screenshot_1583853778

p2 bug

Most helpful comment

A temporary fix would be to just overwrite "onClusterUpdated" with an empty implementation. Seems to fix the issue for me.

All 12 comments

@beli63 Thanks for reporting this. Are you able to share code you used to create the above screenshot?

@barbeau , I use CustomMarkerClusteringDemoActivity Demo's code.
I just put same location in 2 Markers

@beli63 Ok, thanks for the additional info. This may also be related to https://github.com/googlemaps/android-maps-utils/issues/384.

@barbeau Okay thanks

still facing this bug in 1.0.2, any update?

Sorry, no update yet!

I am also encountering this bug. By changing the algorithm to GridBasedAlgorithm it stops the default clustering icon from being shown. However, this introduces other problems.

I am not sure if there is anything erroneous is occurring with the algorithms... hope that helps!

A temporary fix would be to just overwrite "onClusterUpdated" with an empty implementation. Seems to fix the issue for me.

@B3nedikt thanks. Fixed this problem

@B3nedikt Yes I valid, it fixed the problem
Thanks

Looking at the code, it looks like this behavior is new in v1.0 due to a side-effect of PR https://github.com/googlemaps/android-maps-utils/pull/627, part of which fixes an issue with existing markers not reflecting updated contents. For example, as discussed in https://github.com/googlemaps/android-maps-utils/issues/90, prior to https://github.com/googlemaps/android-maps-utils/pull/627 if you updated a marker's position, title, or snippet, that update wouldn't be reflected on the map.

PR https://github.com/googlemaps/android-maps-utils/pull/627 fixes this by updating the cached cluster marker using a new protected method onClusterUpdated(), whose default implementation uses the default design. So, when iterating through the markers to render them the 2nd identical location triggers onClusterUpdated() instead of onBeforeClusterRendered(), which then updates the marker with the default cluster design.

So, to fix this, you should override onClusterUpdated() as @B3nedikt suggested above, but the implementation should be the same as your onBeforeClusterRendered() implementation to avoid any caching issues.

Similarly, you should override the implementation of onClusterItemUpdated() with the same implementation as onBeforeClusterItemRendered().

An aside - the implementation can't be identical because you're working with a Marker instead of MarkerOptions, but it's as simple as changing from the format of markerOptions.title("X") to marker.setTitle("X"))

Please give that a shot and see if it works!

FYI, I've opened a pull request at https://github.com/googlemaps/android-maps-utils/pull/679 which shows the changes discussed above for the CustomMarkerClusteringDemoActivity in the demo app.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CodeHore picture CodeHore  路  4Comments

Ricardo1980 picture Ricardo1980  路  7Comments

TatyanaRTB picture TatyanaRTB  路  3Comments

harold-hernandez30 picture harold-hernandez30  路  3Comments

vardaan picture vardaan  路  6Comments