【问题标题】:Google Maps Android API v2: My location marker always over other markers?Google Maps Android API v2:我的位置标记总是高于其他标记?
【发布时间】:2012-12-10 15:52:11
【问题描述】:

目前正在将使用 Google Maps 的 Android 应用程序迁移到 Google Maps Android v2;我希望地图显示内置位置标记以及自定义标记。 使用以前的库,我曾经在自定义标记“下方”绘制位置标记,使用

mapView.setReticleDrawMode(ReticleDrawMode.DRAW_RETICLE_UNDER);

我在新 API 中找不到类似的选项。我错过了什么吗?

【问题讨论】:

  • 我想我可能有办法解决这个问题。如果您需要,请通知我。

标签: android android-mapview google-maps-android-api-2 android-maps-v2


【解决方案1】:

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

我终于把定位销去掉了,在地图上加了一个类似的Marker和Circle;因为它是一个经典的标记,所以它出现在其他标记的下方。

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));

【讨论】:

  • 非常感谢您的代码 sn-p。但是如何获得准确性呢??
  • getMyLocationAccuracy() 是什么?
  • 自这个 4 年前的答案以来,API 不断发展。您可以使用 location.getAccuracy() developer.android.com/reference/android/location/… 获得准确度
猜你喜欢
  • 2016-07-15
  • 1970-01-01
  • 2013-08-27
  • 1970-01-01
  • 2013-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-14
相关资源
最近更新 更多