Where to save Android GPS (Latitude , Longitude) points?

后端 未结 5 789
一生所求
一生所求 2020-12-05 10:59

On onLocationChanged event I want to save my GPS route (Latitude , Longitude). Later I want to load this data and draw the route.

Who is the best way to do this, by

5条回答
  •  天涯浪人
    2020-12-05 11:59

    Correct me if I'm wrong, but it might be better to convert the double values to strings and then whenever you call them convert them back to doubles. Sounds like a pain, but oracle's website (http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html) says:

    "use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency"

    prefEditor.putString("Latitude", Double.valueOf(loc.getLatitude()).toString());
    

    Then, to call the value

    String latitudeString = pref.getString("Latitude", "0");
    double latitude = Double.parseDouble(latitudeString);
    

    It definitely seems like more of a nuisance, but seems also more likely to return the exact value that you saved, also, instead of something slightly off. And I suppose that would depend on how completely accurate you need the values to be.

    Though, as far as using an array, I'm clueless because I've never needed to use them and have no experience with them.

提交回复
热议问题