我试图从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);
}
答案 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'
答案 1 :(得分:0)
尝试定义实现OnMapReadyCallback接口的私有类 并传递该物体。