【发布时间】:2013-12-13 20:42:33
【问题描述】:
我想知道哪种方法最适合使用 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();
}
...
}
有什么想法吗?
【问题讨论】:
-
我创建了一个类,它会在 GPS 首次修复后立即提供回调:stackoverflow.com/questions/19365035/… 如果对您有帮助,请点赞
-
收集坐标所需的时间对我来说是一个重中之重,所以我不确定我能用多少。
-
好的,但没有什么能阻止您像初学者一样使用融合位置,然后在第一次修复完成后立即切换到 GPS :)
标签: android location google-play-services