谷歌地图精简模式moveCamera到lat lng界限添加不需要的地图填充

时间:2015-01-23 09:43:18

标签: google-maps google-maps-android-api-2 android-maps-v2

我希望地图相机移动到我的LatLngBounds。所以我将地图片段添加到BaseExpandableListAdapter的{​​{1}}和getChildView中的布局我onMapReadymoveCamera

LatLngBounds

我正在根据http://googlemaps.github.io/android-maps-utils/计算边界并且似乎工作正常,因为添加到@Override public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { convertView = inflater.inflate(R.layout.event_child, parent, false); GoogleMapOptions options = new GoogleMapOptions(); options.liteMode(true) .compassEnabled(false) .mapToolbarEnabled(false) .rotateGesturesEnabled(false) .tiltGesturesEnabled(false) .scrollGesturesEnabled(false) .zoomControlsEnabled(false) .zoomGesturesEnabled(false); SupportMapFragment mapFragment = SupportMapFragment.newInstance(options); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(R.id.event_fragment_map, mapFragment, "event_fragment_map").commit(); mapFragment.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { mGoogleMap = googleMap; moveMapAddBounds(); } }); //... } private void moveMapAddBounds(){ mGoogleMap.addPolygon(new PolygonOptions().add(getLatLngBounds().southwest) .add(new LatLng(getLatLngBounds().northeast.latitude, getLatLngBounds().southwest.longitude)) .add(getLatLngBounds().northeast) .add(new LatLng(getLatLngBounds().southwest.latitude, getLatLngBounds().northeast.longitude)) ); mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getLatLngBounds(), 0)); } public LatLngBounds getLatLngBounds() { //random fake latlng and distance LatLng from = new LatLng(51.1113564, 17.0041787); double distance = 1717.906494140625; return new LatLngBounds.Builder(). include(SphericalUtil.computeOffset(from, distance, 0)). include(SphericalUtil.computeOffset(from, distance, 90)). include(SphericalUtil.computeOffset(from, distance, 180)). include(SphericalUtil.computeOffset(from, distance, 270)).build(); } 中的地图的矩形被添加到有效位置但是地图相机被移动到几乎好的位置例外情况是它添加一个随机(?)填充来映射(在矩形的上方和下方对称),如图所示:

enter image description here

我观察到这些填充对于特定的LatLngBounds总是相同的,但它们在不同的LatLngBounds之间是不同的。