I have a Location
object and I want to save it in shared preferences, but I can't because it's an object, so I thought of saving latitude and longitude in shared preferences instead, but the problem is that location.getLatitude()
and location.getLongitude()
return Double
and I can't save Double
in shared preferences, however I can save Float
, so my question is: Is it a good idea to save latitude and longitude as floats instead of doubles? Is there another way that I missed?
Asked
Active
Viewed 318 times
0

Mathew Hany
- 13,310
- 4
- 19
- 16
-
1What do you mean by "I can't save Double in shared preferences" ? – miensol Jun 13 '16 at 12:42
-
2There is no `putDouble` method in the SharedPreferences object. – Mathew Hany Jun 13 '16 at 12:43
-
3http://stackoverflow.com/questions/16319237/cant-put-double-sharedpreferences & http://stackoverflow.com/questions/3604849/where-to-save-android-gps-latitude-longitude-points – lubilis Jun 13 '16 at 12:43
-
here http://stackoverflow.com/questions/16319237/cant-put-double-sharedpreferences – Budius Jun 13 '16 at 12:44
-
I read those but I don't know how to use `Double.doubleToLongBits` in kotlin – Mathew Hany Jun 13 '16 at 12:45
-
2There's a nice search bar on StackOverflow. http://stackoverflow.com/questions/35397116/convert-double-to-bytearray-or-arraybyte-kotlin – OneCricketeer Jun 13 '16 at 12:46
-
1I think the Location object is Parcelable, though, so just store that – OneCricketeer Jun 13 '16 at 12:49