英文:
Display GroundOverlay only when building is entirely within cameraView
问题
如标题所述,我只想在相机完全看到整个建筑物时显示GroundOverlay。我应该如何在onCameraMove()方法中实现此目标?目前,即使建筑物的一部分出现在相机视图中,覆盖层也会出现。
@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();
}
}
}
英文:
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
得分: 1
似乎 Building1
应该是建筑物边界点的列表,并且您应该在循环中检查它们是否全部包含在 bounds
中:
...
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();
}
}
...
英文:
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 in bounds
:
...
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();
}
}
...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论