Ich versuche, die Google Maps API zu implementieren. Ich möchte meine eigene Position auf der Karte sehen und ich möchte, dass es sich ändert, wenn ich mich signifikant bewege. Das Problem ist, dass es keine Fehler gibt, aber es zeigt keine Markierung meiner Position auf der Karte an. Das ist mein onCreate() Methode in der .java-DateiGoogle Maps Android API und aktueller Standort
private GoogleMap mMap;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
public static final String TAG = MapPane.class.getSimpleName();
private final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_pane);
// 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);
// Create the LocationRequest object
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10 * 1000) // 10 seconds, in milliseconds
.setFastestInterval(1 * 1000); // 1 second, in milliseconds
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}//onCreate
Und das ist die Methode, die ich denke, ich bin hier fehlt etwas
public void onConnected(@Nullable Bundle bundle) {
Log.i(TAG, "Location services connected.");
Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (location == null) {
Log.i(TAG, "loc exists");
if (checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|| checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}//if
}//if
else {
handleNewLocation(location);
}//else
}//onConnected
, weil ich nie if-Anweisung in die zweite bekommen. Ich denke, ich brauche zuerst die Erlaubnis des Benutzers? Das manuelle Einschalten des GPS auf meinem Gerät funktioniert auch nicht. Und das Verfahren unten habe ich für auf der Karte die Markierung anzeigt
private void handleNewLocation(Location location) {
Log.d(TAG, location.toString());
double currentLatitude = location.getLatitude();
double currentLongitude = location.getLongitude();
LatLng latLng = new LatLng(currentLatitude, currentLongitude);
MarkerOptions options = new MarkerOptions()
.position(latLng)
.title("I am here!");
mMap.addMarker(options);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
}//handleNewLocation
ich mehr Methoden verwendet, aber ich denke, es gibt keinen Fehler drin. Im AndroidManifest.xml I die
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Wie hoch ist der Wert des Standorts? –
Es ist null, weil ich das "Log.i (TAG," loc existiert ") sehen kann;" in meinem Android Monitor – Qas
hast du die Methoden onStart() und onStop() wie dieses Tutorial https://developer.android.com/training/location/retrieve-current.html? –