如何从活动中调用getMapAsync()

时间:2016-07-04 14:49:16

标签: android dictionary

我试图从An Activity调用getMapAsync(),但是我收到了这个错误:

错误:(109,14)错误:找不到符号方法getMapAsync(CategoryActivity)

public class CategoryActivity extends Activity implements     View.OnClickListener,OnMapReadyCallback {

protected void onCreate(Bundle savedInstanceState) {
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);



    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapContainerLayout);
    mapFragment.getMapAsync(this);
}

2 个答案:

答案 0 :(得分:1)

尝试使用匿名回调:

MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.a_main_maps);
mapFragment.getMapAsync(new OnMapReadyCallback() {
    @Override
    public void onMapReady(GoogleMap googleMap) {
        Log.d(TAG, "onMapReady: ");
    }
});

另外,请确保您拥有最新版本的play-services依赖项(9.2.0):

compile 'com.google.android.gms:play-services-maps:9.2.0'

Add Google Play Services to your project

答案 1 :(得分:0)

尝试定义实现OnMapReadyCallback接口的私有类 并传递该物体。