中心标记图标 (Android)
Center marker icon (Android)
我意识到在标记上设置图标,它将 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));
如何"center"图标可绘制中心的标记位置?
您必须使用 "Anchor" 参数到 select 位置:
https://developers.google.com/android/reference/com/google/android/gms/maps/model/MarkerOptions.html#anchor(float, 浮动)
Specifies the anchor to be at a particular point in the marker image.
The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.
The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).
在提供的 link 中有一个 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));
我意识到在标记上设置图标,它将 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));
如何"center"图标可绘制中心的标记位置?
您必须使用 "Anchor" 参数到 select 位置: https://developers.google.com/android/reference/com/google/android/gms/maps/model/MarkerOptions.html#anchor(float, 浮动)
Specifies the anchor to be at a particular point in the marker image.
The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.
The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).
在提供的 link 中有一个 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));