将地图标记设置为自定义颜色的Android [英] Set map marker to a custom color Android

查看:104
本文介绍了将地图标记设置为自定义颜色的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在某些点向地图添加图钉的应用程序.我希望我的图钉颜色与我们应用程序的主题颜色匹配.抱歉,我真的是菜鸟

I am making an app that adds pins to a map at certain points. I want the color of my pins to match the theme colors of our app. Sorry I'm really a noob

int color = Color.rgb(255, 201, 14);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
final LatLng PERTH = new LatLng(40, -80);
Marker perth = mMap.addMarker(new MarkerOptions()
  .position(PERTH)
  .title("MY PIN")
  .snippet("MAGGIE EATS SNAKE SKINS")
  .draggable(true)
  .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin))
  .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.color)));

.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.color)));不起作用.它不允许我在此处插入自定义颜色.我怎样才能做到这一点?谢谢:)

The .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.color))); does not work. It will not allow me to insert a custom color here. How can I do this? Thanks:)

推荐答案

defaultMarker()方法允许设置自定义颜色,但只能提供色相值.根据android文档:

defaultMarker() method allows to set custom color, but only by providing hue value. According to android documentation:

(色相)值必须大于或等于0且小于360

(Hue) Value must be greater or equal to 0 and less than 360

如果您知道应用程序主题的十六进制或RGB值,则需要进行一些计算(请参见示例)或只需使用一些免费的在线转换器.在您的情况下,色相值为47.

If you know Hex or RGB value of your app theme, you need to do some calculations (see example ) or simply use some free online converter. In your case hue value will be 47.

此外,无需在代码中两次设置.icon()属性.

Also, there is no need to set .icon() property in your code twice.

这篇关于将地图标记设置为自定义颜色的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆