我需要用户的确切位置。所以,我创建了两个听众为:Android获得最佳位置
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mGPSListener);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mNetworkListener);
我倾听来自网络和GPS提供商位置更新,并要检查的双方获得的位置准确性因素,这样我可以挑准确位置。我只是想问我是否使用正确的方式来实现...... ???如果没有,请提供一些指导方针如何做到这一点...... ???
我的示例代码:
if(MyGPSListener.currentLocation != null) {
if(MyNetworkListener.currentLocation != null) {
if(MyGPSListener.currentLocation.getAccuracy() <= MyNetworkListener.currentLocation.getAccuracy()) {
useGPSLocation();
}
else if(MyGPSListener.currentLocation.getAccuracy() > MyNetworkListener.currentLocation.getAccuracy()) {
useNetworkLocation();
}
}
else {
useGPSLocation();
}
}
else if(MyNetworkListener.currentLocation != null){
useNetworkLocation();
}
为什么不试试这个 http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location- in/an/3145655#3145655 –