我正在尝试更改标记的颜色。
我可以使用:
BitmapDescriptorFactory.defaultMarker(float hue)
但是我将RGB颜色转换为色调颜色时遇到问题,我找到了一个解决方案http://www.rapidtables.com/convert/color/rgb-to-hsl.htm并将其设置为函数:
public static float rgbToHue(float r, float g, float b) {
r = r/255;
g = g/255;
b = b/255;
float max = Math.max(r,g);
max = Math.max(max, b);
float min = Math.min(r,g);
min = Math.min(min, b);
float delta = max - min;
float hue = 0;
if(max == r){
System.out.println("r");
hue = 60 * ((g-b)/delta);
}
else if (max == g) {
System.out.println("g");
hue = 60 * (((b-r)/delta)+2);
}
else if (max == b) {
System.out.println("b");
hue = 60 * (((r-g)/delta)+4);
}
System.out.println(hue);
System.out.println("--");
return hue;
}
但结果并没有真正起作用,我有一些负面结果(不在0到360之间)
感谢您的帮助
答案 0 :(得分:1)
您无法使用RGB中的任何值并将其映射为仅色调。在HSL / HSV中还有另外两个值,它们当前在库的内部硬编码为完全饱和度/亮度和全值的一半。
欢迎您在gmaps-api-issues上发布功能请求。
我还建议您不要使用默认的Marker
图标,而是创建自己的图标。
答案 1 :(得分:0)
更改标记颜色
默认情况下,地图标记颜色为RED。 Google地图为标记提供了一组预定义的彩色图标。
// ROSE颜色图标
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
//绿色图标
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
希望这会有所帮助..