如何将OnMapReadyCallback设置为我的MapView实例?

我有一个谷歌地图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中没有这样的方法。

回答:

可以使用

getMapAsync(OnMapReadyCallback callback) 

例如,你的情况

mMapView.getMapAsync(this); 

你可以找到的文档here

以上是 如何将OnMapReadyCallback设置为我的MapView实例? 的全部内容, 来源链接: utcz.com/qa/263670.html

回到顶部