6

Google Maps V2(Android)を経度180°/ -180°(iOS MapKitなど)に制限できますか?clusterinアルゴリズムを実装しようとしているので、ラップアラウンドしたくありません。180/ -180度の分割では、それが困難になります。

赤い線でパンを制限したいのですが:

ここに画像の説明を入力してください

4

2 に答える 2

3

だから私はうまくいくはずの解決策を作成しました。ユーザーが -180 / 180 の境界を越えてマップをパンすると、マップは反対側に反転します。したがって、マップをラップすることは引き続き可能ですが、「危険な」エリアは表示されません。

カスタム MapView を作成する必要がありました。

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;
    }
}

そしてxml:

<com.ieffects.clustermap.CustomMapView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

GoogleMap (mapView.getMap()) の場合:

map.setOnCameraChangeListener(new OnCameraChangeListener() {
    @Override
    public void onCameraChange(CameraPosition position) {
        mapView.correctCamera();
    }
});

これは、ユーザーが危険な領域にマップを「飛ばす」場合に必要です。

于 2013-01-28T14:53:49.927 に答える
1

については、このチュートリアルを参照してくださいv2: http://econym.org.uk/gmap/range.htm - 基本的に、move イベントのリスナーを追加し、範囲外になった場合は move を中止します。v3これは同様に適用できるはずです。

于 2013-01-28T12:00:58.073 に答える