Android 获取最精确的当前坐标
我想知道使用Google Play服务获取绝对最准确的当前坐标的最佳方法。是否要使用Android 获取最精确的当前坐标,android,location,google-play-services,Android,Location,Google Play Services,我想知道使用Google Play服务获取绝对最准确的当前坐标的最佳方法。是否要使用getLastLocation(),如下所示: public class MainActivity extends FragmentActivity implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener { ..
getLastLocation()
,如下所示:
public class MainActivity extends FragmentActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener {
...
// Global variable to hold the current location
Location mCurrentLocation;
...
mCurrentLocation = mLocationClient.getLastLocation();
...
}
public class MainActivity extends FragmentActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener,
LocationListener {
...
// Define the callback method that receives location updates
@Override
public void onLocationChanged(Location location) {
// Report to the UI that the location was updated
String msg = "Updated Location: " +
Double.toString(location.getLatitude()) + "," +
Double.toString(location.getLongitude());
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
...
}
或者使用更新回调,如下所示:
public class MainActivity extends FragmentActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener {
...
// Global variable to hold the current location
Location mCurrentLocation;
...
mCurrentLocation = mLocationClient.getLastLocation();
...
}
public class MainActivity extends FragmentActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener,
LocationListener {
...
// Define the callback method that receives location updates
@Override
public void onLocationChanged(Location location) {
// Report to the UI that the location was updated
String msg = "Updated Location: " +
Double.toString(location.getLatitude()) + "," +
Double.toString(location.getLongitude());
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
...
}
有什么想法吗?
getLastLocation()
不保证是您的当前位置,甚至不保证返回您的位置,如果您对最准确的当前位置感兴趣,那么请求位置更新是您的最佳选择我创建了一个类,在GPS获得第一个修复后立即进行回调:如果它对您有帮助,请向上投票收集坐标所需的时间对我来说非常重要,所以我不确定我能把这个放在多大程度上。好吧,但没有什么能阻止你使用融合定位,就像你已经为初学者做的那样,然后在第一次修复完成后立即切换到GPS:)