我想获得移动当前位置,当我安装应用程序时,比第一次获得正确的纬度,但比每次显示第一次获得位置之后。请给我正确的代码以获得每次正确的纬度。_ 在排序中我的位置未更新,或位置缓存不清楚。->我的代码
公共类 MyLocationListener 实现 LocationListener {
private LocationManager mLocationManager;
private Location currentLocation;
public MyLocationListener(Context context) {
mLocationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
currentLocation = mLocationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
mLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, this);
}
public Location getBestLocationAvailable() {
return currentLocation;
}
@Override
public void onLocationChanged(Location newBestLocation) {
mLocationManager.removeUpdates(this);
currentLocation = newBestLocation;
}
@Override
public void nProviderDisabled(String arg0) {
}
@Override
public void onProviderEnabled(String arg0) {
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
}
}
MyLocationListener loc = new MyLocationListener(MainActivity.this);
位置 location = loc.getBestLocationAvailable(); system.out.println(location.getLatitude()+" "+location.getLongitude);
给我写答案,为什么我会老拉长?