android - 移动相机位置以适应关于标记高度的 LatLngBounds

标签 android google-maps-markers google-maps-android-api-2 google-maps-api-2

我想将相机移动到适合 LatLngBounds 标记高度的位置。到目前为止,我可以使用以下代码来匹配标记的 anchor :

LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker marker : markerList) {
    builder.include(marker.getPosition());
}
LatLngBounds bounds = builder.build();

int padding = getActivity().getResources().getDimensionPixelSize(R.dimen.home_map_padding); // offset from edges of the map in pixels
cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);
mGoogleMap.animateCamera(cameraUpdate);

它产生这样的输出: my output so far 如您所见,底部有空白区域(这是 int padding)。 我希望填充像这样相等:

enter image description here

最佳答案

您的问题与此处发布的问题类似:

Defining a CameraUpdate with LatLngBounds with different padding values

解决方案是将实际 GoogleMap 的顶部填充设置为标记图标的高度。

像这样的事情会做:

Drawable drawable = <YOUR DRAWABLE HERE>;
final int padding = drawable.getIntrinsicHeight();
map.setPadding(0, padding, 0, 0);

我的自定义标记图像看起来像这样(插入标尺以进行比较):

enter image description here

关于android - 移动相机位置以适应关于标记高度的 LatLngBounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28813371/

相关文章:

android - 如何在 cordova 中设置通知 PushPlugin?

java - 重复的 : No setter/field for found on class

javascript - 自定义 Google map 图标(如果值 >=1)

android - 使用集群时如何禁用android map 标记点击自动居中?

android - 使用超过 "hue"设置 defaultMarker 的颜色

javascript - WebView.loadUrl 不起作用,使用 JavaScript 显示空白页面

java - 代码不会在 Android Studio 中编译,但会在 Eclipse 中编译

android - 图钉内带有用户图像的自定义谷歌地图标记

php - 检查给定区域/坐标内点的算法

android - 当用户访问该位置(接近标记)时,我想从 map 中替换标记