Ich habe App erstellt, die mit der Google-Karte arbeiten und es funktioniert gut mit den Google-Karten-Diensten. aber ein Problem erscheint, was es ist. , wenn ich den aktuellen Standort anfordern manchmal arbeiten sie in Ordnung und gibt den genauen aktuellen Standort aber andere Zeiten ist es die letzte aktuelle Position zurückkehren , wo ich bin nicht in. , die mich Lösung Dies ist der Code zur Verfügung stellen kannwarum immer die aktuelle Position mit Google Map und Android manchmal den letzten Standort nicht den aktuellen Standort
private GoogleApiClient mLocationclient;
GoogleMap mMap;
// connect client to the map by take his location
mLocationclient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mLocationclient.connect();
// end connect
// erhalten den aktuellen Standort
public LatLng getCurrentLocation(Context context, GoogleMap mMaps,GoogleApiClient mlocationclient){
LatLng ll=null;
Location currentLocation= LocationServices.FusedLocationApi.getLastLocation(mlocationclient);
if(currentLocation==null)
Toast.makeText(context,"could not connect",Toast.LENGTH_SHORT).show();
else {
ll=new LatLng(
currentLocation.getLatitude(),
currentLocation.getLongitude()
);
}
return ll;
}
, denn das war das letzte Mal, es konnte einen erfolgreichen Standort erhalten. Wenn Sie etwas wirklich genau brauchen, dann sollten Sie einen einmaligen Ort mit den Update-Anforderungen – tyczj
bekommen, also was ist das Problem, um zu verhindern, dass es beim nächsten Mal den aktuellen Standort bekommt. und habe ich meine, die zu hören, um den aktuellen Standort zu ändern –
ja müssen Sie für eine einmalige Standortänderung zu hören – tyczj