Ralf Wickum
Ralf Wickum

Reputation: 3294

How to set the markers icon?

I want to cluster my markers on the GoogleMaps map on my Android device. therefore, I tried this example:

public class GoogleMapClusterItem implements ClusterItem {
public final String name;

public final int profilePhoto; // resource id

public final LatLng mPosition;

public MapClusterItem(double lat, double lng, String name, int pictureResource) {
    this.name = name;
    profilePhoto = pictureResource;
    mPosition = new LatLng(lat, lng);
}

@Override
public LatLng getPosition() {
    return mPosition;
}
}

And then I call in the Main Activity:

for (int i = 0; i < 10; i++) {
        double offset = i / 60d;
        lat = lat + offset;
        lng = lng + offset;
        MapClusterItem offsetItem = new MapClusterItem(lat, lng, "Casa Mia", R.drawable.ic_casa);

        mClusterManager.addItem(offsetItem);
    }

I would like to replace a markers icon with an individial png picture. But there is always the red standard marker symbol.

Where should I call the drawMarker Method then?

As you can see, these are not Marker objects.

Upvotes: 0

Views: 262

Answers (1)

Tafveez Mehdi
Tafveez Mehdi

Reputation: 456

    private void drawMarker(LatLng point, int drawable)
    {
       MarkerOptions markerOptions = new MarkerOptions();
       markerOptions.icon(BitmapDescriptorFactory.fromResource(drawable));
       markerOptions.position(point);
       googleMap.addMarker(markerOptions);
    }

You can use the above method to draw markers where param drawable is the drawable resource id (image) and point is LatLng where the marker has to be drawn.

Upvotes: 2

Related Questions