Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Google Maps marker icon?

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)
like image 706
Zookey Avatar asked Apr 27 '17 12:04

Zookey


People also ask

How do you change the marker image on Google Maps?

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.

Can you change the icon on Google Maps?

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.

How do I change the placemark icon on Google Maps?

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.

How do I change the color of a marker on Google Maps?

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.


2 Answers

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);
like image 190
Gilad Brunfman Avatar answered Oct 16 '22 12:10

Gilad Brunfman


final MarkerOptions marker=new MarkerOptions().position(loc);

marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker4));
mMap.addMarker(marker);
like image 37
Anchal Ajay Avatar answered Oct 16 '22 10:10

Anchal Ajay