Google Map Lite 模式 moveCamera 到 lat lng 边界添加了不需要的地图填充

2023-11-30

我希望地图相机移动到我的 LatLngBounds。所以我将地图片段添加到布局中BaseExpandableListAdapter's getChildView and onMapReady I'll moveCamera to LatLngBounds

@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添加到有效位置,但地图相机移动到几乎良好的位置,除了它向地图添加随机(?)填充(矩形上方和下方对称),如图所示:

enter image description here

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


原因是我使用了精简模式,其中仅提供整数缩放。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Google Map Lite 模式 moveCamera 到 lat lng 边界添加了不需要的地图填充 的相关文章

随机推荐