Android GoogleMaps GroundOverlay Padding

懵懂的女人 提交于 2020-02-27 09:56:12

问题


This post is very similar to This, which does not currently have a solution (3 years old)

The main issue is that GoogleMaps seems to be adding an unnecessary amount of padding around my ground overlay image this doesn't make sense to me since the boundaries are set to the same lat,lngs as the ground overlay.

@Override
public void onMapReady(GoogleMap googleMap) {

    final LatLngBounds NewarkBounds = new LatLngBounds(
            new LatLng(FILL, -FILL),
            new LatLng(FILL, -FILL)
    );

    mMap = googleMap;
    mMap.getUiSettings().setMapToolbarEnabled(false);
    mMap.getUiSettings().setZoomGesturesEnabled(false);
    mMap.getUiSettings().setMyLocationButtonEnabled(false);

    LatLng myPosition = new LatLng(latitude,longitude);


    GroundOverlayOptions newarkMap = new GroundOverlayOptions()
            .image(BitmapDescriptorFactory.fromResource(R.drawable.maptest))
            .positionFromBounds(NewarkBounds)
            .visible(true);

    mMap.addGroundOverlay(newarkMap);



    if((myPosition.latitude <= FILL&& myPosition.latitude >=FILL) && (myPosition.longitude >= -FILL&& myPosition.longitude <= -FILL)){
        mMap.setMyLocationEnabled(true);

    }
    else {
        mMap.setMyLocationEnabled(false);
    }

    mMap.setOnMyLocationButtonClickListener(this);
    mMap.setOnMyLocationClickListener(this);
    mMap.setMapType(0);


    /*
    int width = getResources().getDisplayMetrics().widthPixels;
    int height = getResources().getDisplayMetrics().heightPixels;
    int padding = (int) (width * 0.001); // offset from edges of the map 12% of screen

    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(NewarkBounds, width, height, 0);
    mMap.animateCamera(cu);
    mMap.setPadding(0,0,0,0);
    mMap.setLatLngBoundsForCameraTarget(NewarkBounds);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(NewarkBounds.getCenter(), 17));
    // Set the camera to the greatest possible zoom level that includes the bounds

    */

    mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            // Set the camera to the greatest possible zoom level that includes the bounds
            mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(NewarkBounds, 0));
            //Centering the camera within bounds:
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(NewarkBounds.getCenter(), 17));
            //Restricting the user's scrolling and panning within bounds:
            mMap.setLatLngBoundsForCameraTarget(NewarkBounds);
        }
    });
}

I have tried multiple methods to fix this, I found it is possible to assign different coordinates outside of the bounds to the ground overlay but this is simply incorrect. Below is what the current display shows.

This is what I want to achieve

I would appreciate any thoughts on this issue as it is driving me bonkers. Thank you!

来源:https://stackoverflow.com/questions/60116647/android-googlemaps-groundoverlay-padding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!