【发布时间】:2013-08-13 00:21:47
【问题描述】:
首先,我是一个完整的安卓新手。逐步开发我的第一个应用程序并遇到一些问题。
- 我可以根据纬度和经度获取我的位置,现在我必须将其保存到文件中,并且能够读取文件以在将来比较位置。任何人都可以帮我解决这个问题。
以下是我的错误代码
public void saveCurrentLocation(Location location){
SharedPreferences prefs = this.getSharedPreferences("com.example.mylocation", Context.MODE_PRIVATE);
String currentLat = "com.example.mylocation.location";
String now = prefs.getString(currentLat, location.getLatitude());
}
显示的错误是 location.getLatitude 是一个 double 并且不能保存到字符串(很明显但不确定如何更改它)
谢谢
【问题讨论】:
-
您可以将双精度数转换为字符串(查看Double class),或使用浮点数(但我认为它们对于位置数据不够精确)。
-
我建议你参考以下链接stackoverflow.com/a/17222144/1554935