Trying to put together a little MapFragment in an activity I\'m building, but am having some trouble getting it all to work. I know that the Maps api and Play services are
This is what i had to do, because i was working under level 11;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.support.v4.app.FragmentActivity;
public class MapaActivity extends FragmentActivity {
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mapa);
map = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapa)).getMap();
}
}
Change your dependencies to:
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
I can either use getFragmentManager() or getSupportFragmentManager().
There should be no debate here. If getSupportFragmentManager()
is available to you, then you are using the Android Support package's backport of fragments, and this is the method that you must use.
When I opt for getSupportFragmentManager(), Eclipse doesn't like it and gives me the error "Cannot cast from Fragment to MapFragment".
That is because you should not be using MapFragment
. You are using the Android Support package's backport of fragments, and therefore you must use SupportMapFragment
.
hey simply add v4 jar to your libs folder and add to build then in your Fragment page just import
import android.support.v4.app.FragmentActivity;
you may able to extends FragmentActivity
public class MainActivity extends FragmentActivity implements LocationListener{
}
and it also access getSupportFragmentManager();
SupportMapFragment fm =(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);