Also habe ich eine Lösung, die in Ordnung sein sollte. Wenn der Benutzer die Karte über den Rand -180/180 schwenkt, wird die Karte auf die andere Seite gedreht. Das Umbrechen der Karte ist also weiterhin möglich, aber der "gefährliche" Bereich wird nie angezeigt.
Ich hatte eine benutzerdefinierte MapView zu erstellen:
public class CustomMapView extends MapView {
private double prevLongitude;
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean retVal = correctCamera();
prevLongitude = getMap().getCameraPosition().target.longitude;
return retVal;
}
public boolean correctCamera() {
if (getMap().getProjection().getVisibleRegion().latLngBounds.northeast.longitude < getMap().getProjection().getVisibleRegion().latLngBounds.southwest.longitude) {
double diff = getMap().getProjection().getVisibleRegion().latLngBounds.southwest.longitude - getMap().getProjection().getVisibleRegion().latLngBounds.northeast.longitude;
double longitudeSW;
double longitudeNE;
double longitudeDiff = (360-diff)/25;
// use > 0 if you want the map to jump to the other side
// <= 0 will cause the map to flip back
if (prevLongitude > 0) {
longitudeSW = -180 + longitudeDiff;
longitudeNE = -180 + longitudeDiff - diff;
} else {
longitudeSW = 180 - longitudeDiff + diff;
longitudeNE = 180 - longitudeDiff;
}
LatLngBounds bounds = new LatLngBounds(
new LatLng(getMap().getCameraPosition().target.latitude, longitudeSW),
new LatLng(getMap().getCameraPosition().target.latitude, longitudeNE)
);
getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
return true;
}
return false;
}
}
Und das xml:
<com.ieffects.clustermap.CustomMapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Und für die GoogleMap (mapView.getMap()):
map.setOnCameraChangeListener(new OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
mapView.correctCamera();
}
});
Diese Wird benötigt, wenn der Benutzer die Karte in die gefährliche Region "fliegen" lässt.
Aber das ist in js ?? –