简体   繁体   中英

Change the Color of Marker Option in android?

In my code i am using this sort of code to make a marker option when clicking in a marker .

MarkerOptions op = new MarkerOptions();
                    op.position(point)
                            .title(Location_ArrayList.get(j).getCity_name())
                            .snippet(Location_ArrayList.get(j).getVenue_name())
                            .draggable(true);

                    icon = BitmapDescriptorFactory
                            .fromResource(R.drawable.pin);

在此处输入图片说明

I want to change background color of the marker option and make it to black . How to change it programmatically here.

Use the Icon Factory, as shown here . Just add this to your MarkerOptions.

MarkerOptions op = new MarkerOptions();
 op.position(point)
             .title(Location_ArrayList.get(j).getCity_name())
             .snippet(Location_ArrayList.get(j).getVenue_name())
             .draggable(true)
             .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

Make sure that you then create the Marker with the options:

Marker marker=new Marker(op);

try this..

 Marker melbourne = mMap.addMarker(new MarkerOptions()
.position(MELBOURNE)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

its long overdue but may help someone else looking for this ... You cannot just change the color, what you need to do is use the GoogleMap.InfoWindowAdapter to show the text instead of the more simple title and snippet approach. You need to override the adapter and set it in your map. myMapObject.setInfoWindowAdapter(new MyMarkerInfoWindowAdapter());

see in here: http://www.rogcg.com/blog/2014/04/20/android-working-with-google-maps-v2-and-custom-markers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM