dha*_*nar 6 gps android location
我正在开发一个Android应用程序,其中当前和精确的位置是关键.检测到GPS定位后,它将移至下一个活动.
问题是我在室外进行了测试,发现有时它只是使用了之前修复的位置.
所以我要问的是什么; 有什么其他逻辑可以从LocationManager获取位置而不是getLastKnownLocation吗?我还没有找到一个看起来不像的例子
Location location = locationManager.getLastKnownLocation(provider);
Run Code Online (Sandbox Code Playgroud)
感谢名单!
这是官方指南中的示例代码(几乎没有修改):
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Run Code Online (Sandbox Code Playgroud)
在这里,您只需向 GPS 请求更新,一旦收到位置信息,您就会接到回电。
| 归档时间: |
|
| 查看次数: |
7690 次 |
| 最近记录: |