Jedes Mal, wenn ich die App öffne sagt es leider Ihre App wurde gestoppt. Ich bin nicht in der Lage, den FehlerGoogle Maps - Ich versuche den aktuellen Standort zu aktualisieren, aber meine App ist geschlossen, sobald ich sie öffne. Hier ist der Code-
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
protected LocationManager locationManager;
TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, (android.location.LocationListener) mLocationListener);
}
private final LocationListener mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(final Location location) {
//your code here
tv1 = (TextView) findViewById(R.id.tv1);
tv1.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
}
};
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
}
}
Hier wird das Protokoll Fehler zu finden -
java.lang.RuntimeException: Kann Aktivität ComponentInfo starten {manishsaran.maper/manishsaran.maper.MapsActivity }: java.lang.ClassCastException: manishsaran.maper.MapsActivity $ 1 kann nicht
ich die Lösung gefunden und Das Problem war, dass ich LocationManager (com.google.android.gms.location) anstelle von android.location.LocationListener –