【问题标题】:Getting Most Accurate Current Coordinates获取最准确的当前坐标
【发布时间】: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


【解决方案1】:

getLastLocation() 不能保证是您当前的位置,甚至根本不保证会返回您的位置,如果您对最准确的当前位置感兴趣,那么请求位置更新是您的最佳选择

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 2020-12-11
    相关资源
    最近更新 更多