I've got a problem with the mapMapfragment of GoogleMaps in Android.
I used this Method, which have to be override:
@Override
public void onMapReady(GoogleMap googleMap) {
gm = googleMap;
gm.setMapType(GoogleMap.MAP_TYPE_HYBRID);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.choose_festival_gps_disabled), Toast.LENGTH_SHORT).show();
} else {
gm.setMyLocationEnabled(true);
}
gm.getUiSettings().setZoomControlsEnabled(true);
gm.addMarker(new MarkerOptions().position(new LatLng(latitude(), longitude())).title(name()));
gm.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(latitude(), longitude())));
gm.animateCamera(CameraUpdateFactory.zoomTo(15));
}
Then I called this one in an Async Task:
((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMapAsync(Activity.this);
Now I got two problems, I've searched for a long time but got no clue how to solve it:
The Map zoom is not exactly to my location, maybe 5 km northern of it.
If I open and close the Activity high frequently, I've got the following Fatal Exception.
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.MapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)' on a null object reference