0
In MainActivity.javaMapFragment null zeigt, die Googlemaps führt zu null
try
{
supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
SupportMapFragment.getMapAsync(this);
initializeMap();
}catch (Exception e)
{
e.printStackTrace();
}
onMapReady (GoogleMap googleMap) -Methode in MainActivity.java
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
Context context = this;
googleMap.setMyLocationEnabled(true);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location currentLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
latitudeCurr = currentLocation.getLatitude();
longitudeCurr = currentLocation.getLongitude();
Toast.makeText(MainActivity.this, "lat "+latitudeCurr+" long "+longitudeCurr, Toast.LENGTH_SHORT).show();
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.getUiSettings().setZoomGesturesEnabled(true);
googleMap.getUiSettings().setRotateGesturesEnabled(true);
if (Build.VERSION.SDK_INT >= 23 &&
ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return ;
}
Aber MapFragment wird immer null. Ich habe auch versucht mit
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Bitte helfen.