【问题标题】:Center marker icon (Android)中心标记图标 (Android)
【发布时间】:2015-08-19 14:19:45
【问题描述】:

我意识到将图标设置在标记上,它将 LatLng 中心定位在图标可绘制的底部。我这样设置标记:

BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.mi_posicion_marker);
mMarkerMiPosicion = mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("I am here!").icon(icono));

如何将标记位置“居中”在可绘制图标的中心?

【问题讨论】:

    标签: android google-maps marker


    【解决方案1】:

    您必须使用“Anchor”参数来选择位置: https://developers.google.com/android/reference/com/google/android/gms/maps/model/MarkerOptions.html#anchor(float,浮动)

    指定锚点位于标记图像中的特定点。

    锚点指定图标图像中的点,该点被锚定到地球表面上标记的位置。

    锚点在连续空间[0.0, 1.0] x [0.0, 1.0]中指定,其中(0, 0)是图像的左上角,(1, 1)是图像的下-右上角。 W x H 图像中的锚定点是 (W + 1) x (H + 1) 网格中最近的离散网格点,通过缩放然后舍入获得。例如,在 4 x 2 图像中,锚点 (0.7, 0.6) 解析为 (3, 1) 处的网格点。

    在提供的链接中,有一个 ASCII 图像很好地解释了它是如何管理的。 对于您的具体问题;

    BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.mi_posicion_marker);
    mMarkerMiPosicion = mMap.addMarker(
        new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude()))
        .title("I am here!").icon(icono).anchor(0.5f,0.5f));
    

    【讨论】:

    • 太棒了!锚是关键。非常感谢!!稍微更正一下:anchor(float,float) 然后你放双打:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-08
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多