移动相机的位置就标记的高度以适合的LatLngBounds [英] Move camera position to fit LatLngBounds with regard to marker height

查看:178
本文介绍了移动相机的位置就标记的高度以适合的LatLngBounds的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想移动相机来定位,以适应的LatLngBounds 关于标记的高度。到目前为止,我能够为配合标记与此code主播:

I want to move camera to position to fit LatLngBounds with regard to marker height. So far I'm able for fit the anchors of markers with this code:

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

这会产生这样的输出:

正如你所看到的底部有空白(这是 INT填充)。 我想有填充等于这样的:

推荐答案

您的问题是一个类似张贴在这里:

Your question is similar to the one posted here:

<一个href=\"http://stackoverflow.com/questions/21970158/defining-a-cameraupdate-with-latlngbounds-with-different-padding-values\">Defining用不同的填充值的LatLngBounds一个的CameraUpdate

解决方案是实际的的GoogleMap 顶边距设置为您的标记图标的高度。

The solution is to set the top padding of the actual GoogleMap to the height of your marker icon.

像这样的东西会做什么:

Something like this will do:

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

看起来这与我的自定义标记的图像(插入比较统治者):

Looks like this with my custom marker image (rulers inserted for comparison):

这篇关于移动相机的位置就标记的高度以适合的LatLngBounds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆