谷歌地图Android API v2:我的位置标记总是在其他标记之上?

4

目前正在将使用Google地图的Android应用程序迁移至Google Maps Android v2。 我希望地图能显示内置位置标记以及自定义标记。 在使用先前的库时,我会将位置标记绘制在自定义标记“下方”,具体方法为:

mapView.setReticleDrawMode(ReticleDrawMode.DRAW_RETICLE_UNDER);

我在新API中找不到类似的选项,是我漏掉了什么吗?


我想我可能有一个解决方案。如果你需要的话,就通知我。 - amalBit
1个回答

7

经过一番搜索,我没有找到这样的选项。

最终我移除了位置图钉,并在地图上添加了一个类似的标记和圆圈;由于它是一个传统的标记,它出现在其他标记下面。

map.setMyLocationEnabled(false);

// ...
// get the current location with Android LocationManager in some way
// ...

// then draw it on the map when it changes:
if (null == getMyLocation())
    return;

if (null != locationMarker) {
    locationMarker.remove();
}
if (null != locationCircle) {
    locationCircle.remove();
}
LatLng loc = getMyLocation();

locationMarker = map.addMarker(new MarkerOptions()
        .icon(BitmapDescriptorFactory
                .fromResource(R.drawable.blue_pin_12))
        .position(getMyLocation()).anchor(0.5f, 0.5f));

float accuracy = getMyLocationAccuracy();

locationCircle = map.addCircle(new CircleOptions().center(loc)
            .radius(accuracy)
            .strokeColor(Color.argb(255, 0, 153, 255))
            .fillColor(Color.argb(30, 0, 153, 255)).strokeWidth(2));

Location pin


非常感谢您的代码片段。但是如何获得准确性? - Leo DroidCoder
getMyLocationAccuracy()是什么意思? - Leo DroidCoder
API自那个4年前的答案以来已经发生了变化。您可以使用location.getAccuracy()来获取精度。https://developer.android.com/reference/android/location/Location.html#getAccuracy() - etienne

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接