in my following code, getMap() returns null, which stop the app. If I don\'t do anything with the map (i.e, removing the last two lines), it shows correctly. Any idea why? T
If getMap()
is returning null it's because Map isn't ready yet or GooglePlayServices is out to date. You better use something like that :
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(resultCode != ConnectionResult.SUCCESS)
{
Builder builder = new AlertDialog.Builder(Main.this);
builder.setMessage(getResources().getString(R.string.error_getting_maps));
builder.setCancelable(true);
builder.setPositiveButton("OK", null);
AlertDialog dialog = builder.create();
dialog.show();
} else {
_map = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
[ETC]
}
Duplicate of: SupportMapFragment.getmap() returns null
Check your layout xml file. I noticed that I wasn't referencing: android:name="com.google.android.gms.maps.SupportMapFragment" but rather: android:name="com.google.android.gms.maps.MapFragment"
The name should be: android:name="com.google.android.gms.maps.SupportMapFragment"