我想知道哪种方法最适合使用Google Play服务获取绝对最准确的当前坐标。是否使用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();
}
...
}
有什么想法吗?
答案 0 :(得分:1)
getLastLocation()
并不保证是您当前的位置,如果您对最准确的当前位置感兴趣,那么即使您最感兴趣的位置更新也是您最好的选择