Things I already know
object.icon(BitmapDescriptorFactory.defaultMarker(<color value>));
What do I need? This specific float value for grey
My research: Color wheel Grey is not included in HUE colors. It is in Tone. So how to access color values in Tones.
No grey available as a hue. So one approach is to grab a marker png and modify for grey (externally), as in this snap (that's all the hues plus the special grey one on top). Create BitmapDescriptor from resource:
(For the grey png set transparent color to white.)
Relevant code (not essential for the answer):
public void createMarkers() {
LatLng pos = new LatLng(38.547279, -121.46101);
for (int i = 0; i < 360; i++) {
mMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.defaultMarker(i)).position(pos));
double lat = pos.latitude;
double lng = pos.longitude;
lng += 0.01;
if ((i + 1) % 40 == 0) {
lng = -121.46101;
lat = pos.latitude + 0.01;
}
pos = new LatLng(lat,lng);
}
double lat = pos.latitude + 0.01;
pos = new LatLng(lat, pos.longitude);
BitmapDescriptor bd = BitmapDescriptorFactory.fromResource(R.drawable.ic_map_marker);
mMap.addMarker(new MarkerOptions().icon(bd).position(pos));
}
For those of us who actually want to use the existing hue colors, you can do something like this:
fun MapFragment.addGreenMarker(latLng: LatLng) {
getMap()?.apply {
addMarker(
MarkerOptions()
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))
.position(latLng)
.draggable(true)
)
}
}
When you are typing R.drawable.gr... - it shows up without the .png extension.
Run your app. Basic testing shows that the icon size works on a tablet and phone just fine without worrying about the different resolutions. I will to more testing to see this remains true for higher resolutions.
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.