Android MapBox更改MyLocation标记的样式

时间:2017-07-15 13:29:24

标签: java android mapbox mapbox-marker

我正在使用适用于Android的MapBox API(v5.1)。我设法让它工作得很好,我使用的是自定义样式(灯光样式,但略有修改) 我启用了MyLocation,它也运行得很好。但是在地图上显示我的位置的点(或标记)(在GoogleMaps中为蓝色)是浅灰色的,因此在地图上几乎看不到。 Screenshot of the map with marker 有没有办法改变它的颜色?我已经尝试获取所有的图层,但我无法在MapBox Studio和Android中找到它。我在哪里可以自定义它?

我发现一个可能的solution(虽然它适用于谷歌地图)也可以使用,但在我看来 - 这不是一个好的解决方案。

2 个答案:

答案 0 :(得分:1)

您应该可以通过MyLocationViewSettings对象和setForegroundTintColor方法更改这些设置。

如果您已有MapboxMap,则可以在调用newInstance时通过MapboxMapOptions对其进行配置,但您只能change the accuracy tint color

答案 1 :(得分:0)

现在,在MapboxMap中不推荐显示位置。推荐的解决方案是使用LocationLayerPlugin。

修改 由于0.4.0 Mapbox现在在每个属性之前都有前缀mapbox_。新的样式名称可以在https://github.com/mapbox/mapbox-plugins-android/blob/master/plugin-locationlayer/src/main/res/values/styles.xml找到。

要更改我的位置标记,您可以将自定义样式添加到从mapbox_LocationLayer继承的styles.xml中,并覆盖mapbox_foregroundDrawable项。

<style name="CustomLocationLayer" parent="mapbox_LocationLayer">
    <item name="mapbox_foregroundDrawable">@drawable/location</item>
</style>

然后您可以使用以下样式创建图层:

LocationLayerPlugin(mapView, mapboxMap, locationEngine, R.style.CustomLocationLayer)