【问题标题】:Android Google Maps - getLastKnownLocation returns inaccurate latitude and longitudeAndroid Google Maps - getLastKnownLocation 返回不准确的纬度和经度
【发布时间】:2012-02-29 08:28:07
【问题描述】:

我正在开发一个应用程序,我需要计算与当前位置和其他一些位置的距离。我正在使用 GPS 访问用户当前位置,其他位置坐标存储在数据库中。问题出现在以下sn-p:

@Override
public void onLocationChanged(Location arg0) {
    Log.v("LOCATION LAT", String.valueOf(arg0.getLatitude()));
    currentLocation = arg0; //currentLocation is a global class variable
}

问题是当我向 DDMS 提供坐标时,例如: 纬度:62.639579 Longitude: 17.909689 并记录这些值我得到 Latitude: 62.0 和 Longitude 17.0 。

如果我创建一个位置对象并自己设置 lat 和 lng 值,它就可以工作。像这样:

@Override
public void onLocationChanged(Location arg0) {
    Location current = new Location("Current location");
    current.setLatitude(62.639579);
    current.setLongitude(17.909689);
    Log.v("Current LAT", "" + current.getLatitude());
}

编辑已解决:
发现了问题。我给 DDMS 提供了错误的格式。显然这应该用逗号分隔,而不是点...

【问题讨论】:

    标签: android google-maps google-maps-mobile


    【解决方案1】:

    您是否使用了本文中指定的权限?否则,它会重新使用蜂窝塔三角测量。 Other question

    【讨论】:

    • 您好,Jay,感谢您的快速响应。在我发布问题的那一刻,我发现了问题:P 请参阅上面的解决方案。
    【解决方案2】:

    发现问题。我给 DDMS 提供了错误的格式。显然坐标应该用逗号分隔,而不是点...

    【讨论】:

      【解决方案3】:

      您可以执行如下操作。创建一个位置变量,您必须分配位置更改变量

      @Override
      public void onLocationChanged(Location arg0) {
          Location current = new Location("Current location");
          current=arg0;
          Log.v("Current LAT", "" + current.getLatitude());
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-01
        • 2011-11-29
        • 1970-01-01
        相关资源
        最近更新 更多