Display GroundOverlay only when building is entirely within cameraView

Viewed 45

As stated in the title, essentially I only want to display the GroundOverlay when the camera is in view of the entire building. How would I accomplish this within the onCameraMove() method? As of now the overlay appears even when part of the building is within the camera view.

@Override
    public void onCameraMove(){
        LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
        private static final LatLng Building1 = new LatLng(54.69726685890506,-2.7379201682812226);

        if(mMap.getCameraPosition().zoom > 17){
            if (bounds.contains(Building1)) {
                  displayOverlay(); 
            }
         }
1 Answers

It seems that Building1 should be a list of the boundary points of the building, and you should check in a loop that ALL of them are contained inbounds:

...
List<LatLng> buildingPoints = new ArrayList<>();
buildingPoints.add(new LatLng(...,...))
buildingPoints.add(new LatLng(...,...))
...

...
if(mMap.getCameraPosition().zoom > 17){
    boolean allPointsVisible = true;
    for (LatLng currBuildingPoint: buildingPoints) {
        if (!bounds.contains(currBuildingPoint)) {
            allPointsVisible = false;
            break;
        }
    }
    if (allPointsVisible) {
        displayOverlay();
    }
 }
 ...
Related