在我的应用程序中,我以编程方式使用谷歌地图,但是当我调用 getMap() 时,它返回 null。即使我尝试过 onActivityCreated() 但它仍然返回 null。有人请帮助我..这是我的代码,
public void callMap() {
try {
int status = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(mActivity);
if (status == ConnectionResult.SUCCESS) {
Log.d("sreedhu", "Google Play Service Available");
gmo = (new GoogleMapOptions()).zoomControlsEnabled(true)
.rotateGesturesEnabled(true);
mapFragment = SupportMapFragment.newInstance(gmo);
map=mapFragment.getMap();
manager=getFragmentManager();
FragmentTransaction fragmentTransaction = manager
.beginTransaction();
fragmentTransaction.add(R.id.mapFragmentHole, mapFragment);
fragmentTransaction.commit();
manager.executePendingTransactions();
mapFragment=getMap();
} else if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
ErrorDialogFragment.newInstance(status).show(
getFragmentManager(), "errorDialog");
} else {
Toast.makeText(mActivity, "Google Map v2 not available",
Toast.LENGTH_LONG).show();
mActivity.popFragments();
}
} catch (Exception e) {
Log.d("sreedhu", "play" + e.toString());
}
}