使用我标准设置的Google地图API v2,它似乎允许在现有地图数据范围之外滚动。实际上,存在一个滚动限制,但它似乎相当远离实际的地图边界。
有没有简单的方法来解决这个问题?
使用我标准设置的Google地图API v2,它似乎允许在现有地图数据范围之外滚动。实际上,存在一个滚动限制,但它似乎相当远离实际的地图边界。
有没有简单的方法来解决这个问题?
// First set the bounds
private static final LatLng NORTHEAST = new LatLng("LAT HERE", "LNG HERE");
private static final LatLng SOUTHWEST = new LatLng("LAT HERE", "LNG HERE");
private static final LatLngBounds BOUNDS = new LatLngBounds(SOUTHWEST, NORTHEAST);
这个方法看起来像这样:
if (BOUNDS.contains(googleMap.getCameraPosition().target)) {
return;
}
double x = googleMap.getCameraPosition().target.longitude;
double y = googleMap.getCameraPosition().target.latitude;
double maxX = BOUNDS.northeast.longitude;
double maxY = BOUNDS.northeast.latitude;
double minX = BOUNDS.southwest.longitude;
double minY = BOUNDS.southwest.latitude;
if (x < minX) {
x = minX;
}
if (x > maxX) {
x = maxX;
}
if (y < minY) {
y = minY;
}
if (y > maxY) {
y = maxY;
}
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(y, x)));
希望这是你要找的。