10

パン アニメーションが完了した後にマップの中心を検出できる Android Maps API を使用する方法はありますか? この情報を使用して、サーバーから動的にマーカーをロードしたいと考えています。ありがとうBD

4

3 に答える 3

12

また、マップの移動が終了した直後にマップの中心を検出する「did end drag」ソリューションも探していました。私はそれを見つけていないので、うまく機能するこの単純な実装を作成しました:

private class MyMapView extends MapView {

    private GeoPoint lastMapCenter;
    private boolean isTouchEnded;
    private boolean isFirstComputeScroll;

    public MyMapView(Context context, String apiKey) {
        super(context, apiKey);
        this.lastMapCenter = new GeoPoint(0, 0);
        this.isTouchEnded = false;
        this.isFirstComputeScroll = true;
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN)
            this.isTouchEnded = false;
        else if (event.getAction() == MotionEvent.ACTION_UP)
            this.isTouchEnded = true;
        else if (event.getAction() == MotionEvent.ACTION_MOVE)
            this.isFirstComputeScroll = true;
        return super.onTouchEvent(event);
    }
    @Override
    public void computeScroll() {
        super.computeScroll();
        if (this.isTouchEnded &&
            this.lastMapCenter.equals(this.getMapCenter()) &&
            this.isFirstComputeScroll) {
            // here you use this.getMapCenter() (e.g. call onEndDrag method)
            this.isFirstComputeScroll = false;
        }
        else
            this.lastMapCenter = this.getMapCenter();
    }
}

それだけです、お役に立てば幸いです!o/

于 2011-09-19T17:07:58.187 に答える
3

を使用していMapActivityますか? 使用したコードは次のとおりです。

MapView mapView = (MapView)findViewById(R.id.map);
Projection projection = mapView.getProjection();
int y = mapView.getHeight() / 2; 
int x = mapView.getWidth() / 2;

GeoPoint geoPoint = projection.fromPixels(x, y);
double centerLatitude = (double)geoPoint.getLatitudeE6() / (double)1E6;
double centerLongitude = (double)geoPoint.getLongitudeE6() / (double)1E6;

次のようなコードも追加する必要があります。

@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
    boolean result = super.dispatchTouchEvent(event);
    if (event.getAction() == MotionEvent.ACTION_UP)
        reload_map_data();    ///  call the first block of code here
    return result;
}
于 2009-11-20T23:00:57.423 に答える
0

2016 年 8 月以降、Android 用マップはonCameraMoveStarted(および移動の理由などのイベントを検出できるようになりましREASON_GESTUREREASON_DEVELOPER_ANIMATION

次のコード (主にdocsから取得) は、達成できることのアイデアを提供します。

public class MyCameraActivity extends FragmentActivity implements
        OnCameraMoveStartedListener,
        OnCameraMoveListener,
        OnCameraMoveCanceledListener,
        OnCameraIdleListener,
        OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_camera);

        SupportMapFragment mapFragment =
            (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap map) {
        mMap = map;

        mMap.setOnCameraIdleListener(this);
        mMap.setOnCameraMoveStartedListener(this);
        mMap.setOnCameraMoveListener(this);
        mMap.setOnCameraMoveCanceledListener(this);

        // Show Sydney on the map.
        mMap.moveCamera(CameraUpdateFactory
                .newLatLngZoom(new LatLng(-33.87365, 151.20689), 10));
    }

    @Override
    public void onCameraMoveStarted(int reason) {

        if (reason == OnCameraMoveStartedListener.REASON_GESTURE) {
            Toast.makeText(this, "The user gestured on the map.",
                           Toast.LENGTH_SHORT).show();
        } else if (reason == OnCameraMoveStartedListener
                                .REASON_API_ANIMATION) {
            Toast.makeText(this, "The user tapped something on the map.",
                           Toast.LENGTH_SHORT).show();
        } else if (reason == OnCameraMoveStartedListener
                                .REASON_DEVELOPER_ANIMATION) {
            Toast.makeText(this, "The app moved the camera.",
                           Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onCameraMove() {
        Toast.makeText(this, "The camera is moving.",
                       Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onCameraMoveCanceled() {
        Toast.makeText(this, "Camera movement canceled.",
                       Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onCameraIdle() {
        Toast.makeText(this, "The camera has stopped moving.",
                       Toast.LENGTH_SHORT).show();
        // Here you get the camera center
        GeoPoint geoPoint = projection.fromPixels(mMap.getHeight() / 2, mMap.getWidth() / 2);
        double centerLat = (double)geoPoint.getLatitudeE6() / (double)1E6;
        double centerLng = (double)geoPoint.getLongitudeE6() / (double)1E6;
    }
}
于 2016-08-02T08:22:06.067 に答える