2

Googleマップがロードされた後(マップタイルが埋められた後)何かしたいのですが、それを達成する方法はありますか?

4

1 に答える 1

0

qubzで指摘されているように、ViewTreeObserver を使用して、マップの読み込みが完了した後にコールバックを実行できるため、ユーザーは起動直後に正しい場所などを取得できます。

@Override
public void onCreate(Bundle savedInstanceState) {
    // This is a small hack to enable a onMapLoadingCompleted-functionality to the user.
    final View mapView = getSupportFragmentManager().findFragmentById(R.id.google_map_fragment).getView();
    if (mapView.getViewTreeObserver().isAlive()) {
        mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @SuppressWarnings("deprecation")
            // We use the new method when supported
            @SuppressLint("NewApi")
            // We check which build version we are using.
            @Override
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
                // Send notification that map-loading has completed.
                onMapFinishedLoading();
            }
        });
    }
}

protected void onMapFinishedLoading() {
    // Do whatever you want to do. Map has completed loading at this point.
    Log.i(TAG, "Map finished loading.");
    GoogleMap mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.google_map_fragment))
                    .getMap();
    mMap.moveCamera(CameraUpdateFactory.zoomIn());
} 
于 2013-06-10T02:44:29.543 に答える