仅在地面覆盖上限制摄影机?谷歌地图Android API v2
我试图向我的用户显示一个带有标记的地面覆盖图。我试图将视图限制为仅放置在地图上的此图像。我希望用户只看到地图上的地面覆盖图像,而不能看到周围的地图。如果他们越过边缘,手势就会被阻挡 我想要这样的东西: 我不想要这个: 或者这个: 我试图将我的仅在地面覆盖上限制摄影机?谷歌地图Android API v2,android,google-maps,gmsmapview,gmsgroundoverlay,Android,Google Maps,Gmsmapview,Gmsgroundoverlay,我试图向我的用户显示一个带有标记的地面覆盖图。我试图将视图限制为仅放置在地图上的此图像。我希望用户只看到地图上的地面覆盖图像,而不能看到周围的地图。如果他们越过边缘,手势就会被阻挡 我想要这样的东西: 我不想要这个: 或者这个: 我试图将我的map.setLatLngBoundsForCameraTarget()设置为我的图像边界,但结果与上一幅图像类似 我尝试的下一件事是在地面覆盖周围设置一组LatLng对象,并使用curScreen.contains(customMapDetection
map.setLatLngBoundsForCameraTarget()
设置为我的图像边界,但结果与上一幅图像类似
我尝试的下一件事是在地面覆盖周围设置一组LatLng
对象,并使用curScreen.contains(customMapDetectionPoints.get(LatLng对象))
检查它们是否出现在视口中。它确实有效,但我无法阻止相机越过边缘
这里是我迄今为止的测试代码:
private GroundOverlay groundOverlay;
private GoogleMap globalMap;
private final int DETECTION_POINTS_CUSTOM_MAP = 20;
private List<LatLng> customMapDetectionPoints = new ArrayList<>();
//Fully Working as suppose to
@Override
public void onMapReady(GoogleMap map) {
//Other Stuff...
LatLngBounds mapBounds = groundOverlay.getBounds();
map.setLatLngBoundsForCameraTarget(mapBounds);
globalMap = map;
LatLng northwest = new LatLng( mapBounds.northeast.latitude, mapBounds.southwest.longitude);
LatLng northeast = mapBounds.northeast;
LatLng southeast = new LatLng( mapBounds.southwest.latitude, mapBounds.northeast.longitude);
LatLng southwest = mapBounds.southwest;
//My ground overlay is rectangle so I don't need to follow a path or something like that
setDetectionPoints(northwest, southwest);
setDetectionPoints(northeast, southeast);
setDetectionPoints(northwest, northeast);
setDetectionPoints(southwest, southeast);
map.setOnCameraMoveStartedListener(new GoogleMap.OnCameraMoveStartedListener() {
@Override
public void onCameraMoveStarted(int i) {
LatLngBounds curScreen = globalMap.getProjection().getVisibleRegion().latLngBounds;
CameraPosition cameraPosition = globalMap.getCameraPosition();
for (int x =0;x<customMapDetectionPoints.size();x++) {
if (curScreen.contains(customMapDetectionPoints.get(x))) {
cancelMapMovement(cameraPosition);
Log.d("OUT", "Ground Overlay is outside viewport");
return;
} else {
globalMap.getUiSettings().setAllGesturesEnabled(true);
Log.d("IN", "Ground Overlay is inside viewport");
}
}
}
});
//Add 20 new location between two location
//Fully Working as suppose to
public void setDetectionPoints(LatLng fromPos, LatLng toPos) {
double pointLatitude = fromPos.latitude;
double pointLongitude = fromPos.longitude;
double addingValue;
if (fromPos.latitude == toPos.latitude) {
addingValue = (toPos.longitude - fromPos.longitude)/DETECTION_POINTS_CUSTOM_MAP;
for (int i = 0; i < DETECTION_POINTS_CUSTOM_MAP; i++) {
pointLongitude += addingValue;
LatLng pointsPos = new LatLng(pointLatitude, pointLongitude);
customMapDetectionPoints.add(pointsPos);
}
} else if (fromPos.longitude == toPos.longitude) {
addingValue = (toPos.latitude - fromPos.latitude)/DETECTION_POINTS_CUSTOM_MAP;
for (int i = 0; i < DETECTION_POINTS_CUSTOM_MAP; i++) {
pointLatitude += addingValue;
LatLng pointsPos = new LatLng(pointLatitude, pointLongitude);
customMapDetectionPoints.add(pointsPos);
}
}
}
//The problem is here!
public void cancelMapMovement(CameraPosition camPos ) {
//HOW CAN I STOP THE MOVEMENT OVER THE GROUND OVERLAY EDGE
//And make sure that the user dosen't see over the edge
globalMap.getUiSettings().setAllGesturesEnabled(false);
globalMap.moveCamera(CameraUpdateFactory.newCameraPosition(camPos));
}
private groundovery;
私有谷歌地图全球地图;
私有最终整数检测点自定义映射=20;
私有列表customMapDetectionPoints=new ArrayList();
//完全按照设想的那样工作
@凌驾
已于4月1日公开作废(谷歌地图){
//其他东西。。。
LatLngBounds mapBounds=groundOverlay.getBounds();
map.setLatLngBoundsForCameraTarget(mapBounds);
全球地图=地图;
LatLng northwest=新LatLng(mapBounds.northwest.latitude,mapBounds.southwest.Lattude);
LatLng northeast=mapBounds.northeast;
LatLng东南=新LatLng(mapBounds.southwest.latitude,mapBounds.Northwest.Lattude);
LatLng西南=mapBounds.southwest;
//我的地面覆盖层是矩形的,所以我不需要沿着路径或类似的东西走
设定检测点(西北、西南);
设定检测点(东北、东南);
设定检测点(西北、东北);
设定检测点(西南、东南);
setOnCameraMoveStartedListener(新的GoogleMap.OnCameraMoveStartedListener(){
@凌驾
启动CameraMoveStarted后的公共无效(int i){
LatLngBounds curScreen=globalMap.getProjection().getVisibleRegion().LatLngBounds;
CameraPosition CameraPosition=globalMap.getCameraPosition();
对于(int x=0;我对setlatlngboundsforcameratatarget()有着完全相同的问题)
-它在我的地面覆盖层周围添加了填充。你找到原因了吗?或者找到了修复方法了吗?没有,我尝试了不同的东西,但它从来没有按照我想要的方式工作。不过我仍然在等待解决方案!我唯一能想到的可能是与瓷砖的工作方式有关。瓷砖是256x256像素,如果你的覆盖层没有与t的开始对齐ile时,它会将其相交的平铺作为边界,从而错误地计算边界。