Google Map Lite Mode moveCamera to lat lng bounds 添加不需要的地图填充

Google Map Lite Mode moveCamera to lat lng bounds adds unwanted map padding

我想让地图相机移动到我的 LatLngBounds。所以我将地图片段添加到 BaseExpandableListAdaptergetChildViewonMapReady 中的布局 我将 moveCameraLatLngBounds

@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();
}

我正在根据 http://googlemaps.github.io/android-maps-utils/ 计算边界,它似乎工作正常,因为在 moveMapAddBounds 中添加到地图的矩形已添加到有效位置,但地图相机已移动到几乎正确的位置除了它添加了一个随机(?)填充到地图(在矩形上方和下方对称)之外,如图所示:

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

原因是我使用了精简模式,其中只有整数缩放可用。

http://code.google.com/p/gmaps-api-issues/issues/detail?id=7573&q=apitype%3AAndroid2%20type%3ADefect&sort=-id%20-stars&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Internal%20Stars