I want to change selected marker icon on Google Maps, so I have following code:
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
if (null != currentMarker) {
currentMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_arrowautougasen));
}
currentMarker = marker;
currentMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_autoselektovan));
return true;
}
});
googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
if(null != currentMarker) {
currentMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_arrowautougasen));
}
currentMarker = null;
}
});
On this line I get error from below:
if(null != currentMarker) {
currentMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_arrowautougasen));
}
Here is the exception:
java.lang.IllegalArgumentException: Unmanaged descriptor
at com.google.maps.api.android.lib6.common.k.b(:com.google.android.gms.DynamiteModulesB:162)
at com.google.maps.api.android.lib6.impl.o.c(:com.google.android.gms.DynamiteModulesB:75)
at com.google.maps.api.android.lib6.impl.db.a(:com.google.android.gms.DynamiteModulesB:334)
at com.google.android.gms.maps.model.internal.q.onTransact(:com.google.android.gms.DynamiteModulesB:204)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.model.internal.zzf$zza$zza.zzL(Unknown Source)
at com.google.android.gms.maps.model.Marker.setIcon(Unknown Source)
at ba.kordinata.kogps.live.map.MapFragment$5.onMapClick(MapFragment.java:212)
Customizing a map marker }); Adds the icon property to the MarkerOptions object, to change the marker's icon. The icon property can be either a string (the URL to the marker icon), or an Icon object. See the customized marker icon below.
Choose a vehicle icon Learn how to navigate to a place. Tap the blue arrow, or the vehicle if you already changed it. Tap the icon you want to use.
In the left panel under "My Places," right-click the placemark you want to change. Then, click Properties (Windows, Linux) or Get Info (Mac). To the right of the "Name" field, click the placemarks button. Choose a new icon.
To edit the marker color, click or tap on the marker icon. When you do that, you can change both the color of the marker and its style. Go for the color or style you want to change and then click OK to see the effect. Click on the button labeled Done to save your new marker color settings.
This is how I set a drawable
as a marker
on Google Maps:
mMap = googleMap;
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.your_drawable_here);
LatLng sydney = new LatLng(-33.852, 151.211);
MarkerOptions markerOptions = new MarkerOptions().position(sydney)
.title("Marker in Sydney")
.snippet("snippet snippet snippet snippet snippet...")
.icon(icon);
mMap.addMarker(markerOptions);
final MarkerOptions marker=new MarkerOptions().position(loc);
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker4));
mMap.addMarker(marker);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With