问题
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