Search code examples
androidgoogle-maps-markersandroid-maps-extensions

Changing the marker icon using android-maps-extensions


I moved to android-maps-extensions for clustering. But I want to change the icons of the markers during runtime. In the original google maps lib markers have a setIcon method, that is missing in the extension lib. Would it be feasible to add the method to the Marker implementation or should I look for another workaround like deleting the marker and add a new one instead of changing the icon?


Solution

  • Version 1.3.1 you can directly download from the project site, didn't have setIcon added.

    The currect status is version 1.4 is about to be released and it includes both setIcon and setAnchor. I have some problems with uploading zip file to code.google.com.

    If you don't want to use git to clone the repository, you may grab the latest version from GitHub repo: https://github.com/mg6maciej/android-maps-extensions/archive/master.zip

    Note that setIcon will only work for Markers you add to the map. You will not be able to change clusters icons this way for now.

    Edit:

    Changing ClusterMarker.setIcon code from

    @Override
    public void setIcon(BitmapDescriptor icon) {
        throw new UnsupportedOperationException();
    }
    

    to something like:

    @Override
    public void setIcon(BitmapDescriptor icon) {
        if (virtual != null) {
            virtual.setIcon(icon);
        }
    }
    

    should work in most cases.