2017-12-18 233 views
-1

我有一個谷歌地圖API在我的佈局提供MapView如何將OnMapReadyCallback設置爲我的MapView實例?

<com.google.android.gms.maps.MapView xmlns:map="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/map_view" 
... 
/> 

在我的片段,我實現了OnMapReadyCallback

public class MyFragment extends Fragment implements OnMapReadyCallback { 

    // onCreate, onCreateView are not showing here but I have them. 

    @BindView(R.id.map_view) 
    MapView mMapView; 

    // this is the method form the interface I am implementing. 
    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     Log.d("MyFragment", "map ready!"); 
    } 
} 

正如你可以在上面看到,我已經重寫了onMapReady(GoogleMap googleMap)因爲我實施OnMapReadyCallback界面。

但是,如何設置mMapView的聽衆收聽地圖準備事件?

我試過mMapView.setOnMapReadyCallback(this)MapView中沒有這樣的方法。

回答

0

可以使用

getMapAsync(OnMapReadyCallback callback) 

例如,你的情況

mMapView.getMapAsync(this); 

你可以找到的文檔here

相關問題