我想将坐标从Google地图中的标记保存到SharedPrefrences,以便我可以在其他活动中访问它。这就是我如何得到我的谷歌地图活动坐标:Android - 如何将坐标从Google Maps API保存到SharedPreferences并检索它?
LatLng mlatLng = new LatLng(location.getLatitude(), location.getLongitude());
我想将坐标从Google地图中的标记保存到SharedPrefrences,以便我可以在其他活动中访问它。这就是我如何得到我的谷歌地图活动坐标:Android - 如何将坐标从Google Maps API保存到SharedPreferences并检索它?
LatLng mlatLng = new LatLng(location.getLatitude(), location.getLongitude());
试试这个保存共享偏好:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
sharedPreferences.edit().putString("lat_lng",mlatLng).apply();
为了得到共享偏好值:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
sharedPreferences.getString("lat_lng","");
我希望这将帮帮我。
“lat_lng”之后的“”之间是什么? – Mozy
Nothing,只是一个默认的空字符串。 –
将其另存为json字符串,稍后您可以将其恢复。 – Krish