本文介绍了用LatLngBounds定义一个带有不同填充值的CameraUpdate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个函数允许为 MapFragment 的不同边缘指定默认填充值,即类似于



CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds,int padding)



已经存在,但是像



CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds,int paddingTop,int paddingLeft,int paddingBottom,int paddingRight)



为什么我需要这个:在我的MapFragment中,顶部有一个半透明层。因此,我需要在顶部比底部更宽的填充。




我发现了类似的问题:。但是,在我的情况下,获取投影和滚动X像素是不够的,因为我不仅想滚动(平移)。我使用带有newLatLngBounds(bounds,padding)的CameraUpdate,它应该 zoom pan。所以在相机更新之前我有一个不同的投影。



我希望我明白这个问题!

解决方案

一个设置填充地图的例子...



在地图上设置填充。



这种方法可以让你以在地图上定义可见区域,以通过在地图的四个边缘中的每一个上设置填充来向地图发信号通知地图的围绕边缘的部分可能被遮挡。地图功能将适应填充。例如,缩放控件,指南针,版权声明和Google徽标将被移动以适应定义的区域,相机移动将相对于可见区域的中心等。

*大小以像素为单位

  GoogleMap.setPadding(10,20,20,50); 

全部为Int left,top,right,bottom

来自@MaciejGorsky,这里是文档...




Is there a function that allows specifying default padding values for different edges of the MapFragment, i.e. similar to

CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds, int padding)

which already exists, but instead something like

CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds, int paddingTop, int paddingLeft, int paddingBottom, int paddingRight)?

Why I need this: In my MapFragment I have a half transparent layer on top. Therefore I need a wider padding at the top than at the bottom.

I found this similar question: Offseting the center of the MapFragment for an animation moving both the target lat/lng and the zoom level. However, getting the projection and scrolling by X pixels is not enough in my case, because I don't only want to scroll (pan). I use a CameraUpdate with newLatLngBounds(bounds, padding), which is supposed to both zoom and pan. So I have a different projection before the camera update.

I hope I made the question clear!

解决方案

This is an example of set padding to map...

Sets padding on the map.

This method allows you to define a visible region on the map, to signal to the map that portions of the map around the edges may be obscured, by setting padding on each of the four edges of the map. Map functions will be adapted to the padding. For example, the zoom controls, compass, copyright notices and Google logo will be moved to fit inside the defined region, camera movements will be relative to the center of the visible region, etc.

*the size is in pixels

GoogleMap.setPadding(     10,      20,      20,     50);

    all are Int                       left,        top,       right,  bottom

from @MaciejGorsky, here is the documentation...

https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap?hl=pl#setPadding(int, int, int, int)

这篇关于用LatLngBounds定义一个带有不同填充值的CameraUpdate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 00:58