Ich habe Google Map in Android-App integriert funktioniert alles gut, aber wenn die App erkennt, dass das GPS des Handys nicht aktiviert ist gibt es ein Dialogfeld zu GPS aktivieren und wenn der Benutzer dies tut und zur Anwendung zurückkehrt, reagiert die Karte nicht mehr und wird blau (kann sich im Ozean konzentrieren) und wenn ich das Gerät schüttele, wird die Karte aktiv und konzentriert sich auf den aktuellen Standort des Benutzers.Meine Google-Karte funktioniert nicht, nachdem Benutzer GPS aktiviert und die Anwendung
Ich möchte diese App im Hochformat ausführen, so dass die Shake-Option nicht sehr hilfreich sein wird.So kann mir jemand mit dem Code helfen und mir sagen, wo ich falsch liege. Ich habe versucht, verschiedene Links und Methoden in onResume, onRestart, aber nichts war hilfreich.
Hier ist mein Code Ich rufe diese setupmapifneeded Funktion in onCreate, onResume und in onRestart, aber nichts ist hilfreich.
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mapFragment == null) {
// Try to obtain the map from the SupportMapFragment.
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
// creating GPS Class object
gps = new GPSTracker(MainActivity.this);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(gps.getLatitude(), gps.getLongitude()), 15.0f));
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(26.89209, 75.82759))
.title("FUN N FOOD"));
// check if GPS location can get
if (gps.canGetLocation()) {
Log.d("Your Location", "latitude:" + gps.getLatitude() + ", longitude: " + gps.getLongitude());
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(gps.getLatitude(), gps.getLongitude()), 15.0f));
} else {
gpsDialog = new MaterialDialog.Builder(MainActivity.this)
.titleColor(getResources().getColor(R.color.grey))
.title("GPS Settings")
.content("GPS is not enabled. Do you want to go to settings menu?")
.positiveText("Settings")
.negativeText("Cancel")
.positiveColorRes(R.color.grey)
.negativeColorRes(R.color.grey)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
gpsDialog.dismiss();
}
})
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
gpsDialog.dismiss();
}
})
.show();
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(gps.getLatitude(), gps.getLongitude()), 14.0f));
}
}
});
}
}
hier ist mein activity.main
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
und hier ist meine andere Methoden
@Override
public void onPause() {
if (mAdView != null) {
mAdView.pause();
}
super.onPause();
}
@Override
public void onResume() {
super.onResume();
if (mAdView != null) {
mAdView.resume();
}
if (mapFragment == null) {
setUpMapIfNeeded();
}
}
@Override
protected void onRestart() {
super.onRestart();
if (mapFragment == null) {
setUpMapIfNeeded();
}
}
@Override
public void onDestroy() {
if (mAdView != null) {
mAdView.destroy();
}
super.onDestroy();
}
Jeder kann dieser etwas ... Vielen Dank im Voraus
SRY aber Es war nicht hilfreich genug –