How to store the LatLng variable in Android in an SQL Lite Database for use later?
Solution 1
I solved it by doing this:
LatLng latLng;
Double l1=latlng.latitude;
Double l2=latlng.longitude;
String coordl1 = l1.toString();
String coordl2 = l2.toString();
l1 = Double.parseDouble(coordl1);
l2 = Double.parseDouble(coordl2);
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(l1, l2))
.title(title)
.snippet(info));
So from a Latlng variable to two doubles, to strings,back to doubles and passed to newmarker position and it works!
:)
Solution 2
i save lat and long seperate, maybe this is also a solution for you
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
Solution 3
As an alternative you could store the position in the SharedPreferences
. Here is the TypedPreferences library and the LatLngPreference
helper class to do this easily.
Comments
-
deucalion0 almost 2 years
I am trying to store marker information in an SQL Lite database on an Android device, I am currently converting the
LatLng
variable to aString
and saving that way.LatLng latLng coords = latLng.toString();
The problem is, and I have tried many things, is converting the
string
back to alatLng
variable so it can be used again.Looking into the
LatLng
variable I see it is twodoubles
separated by a comma, I was thinking about splitting thestring
and converting todoubles
then passing that as aLatlng
but I don't know how to do this in Android.Any ideas on how to do this?