I have an application where I am getting the latitude and longitude coordinates.
I want , when to press a button to start navigating to that position .
Now ,
In the example below ImplLocationService
is a class/service within my application that is providing the latitude and longitude coordinates of the current location within the device. The Location
class is similar to Android's offering but is slightly different and is providing the destination latitude and longitude coordinates. If you were to pull these values from a database, the approach below is the same.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" +
ImplLocationService.getCurrentLocation().getLatitude() + "," +
ImplLocationService.getCurrentLocation().getLongitude() + "&daddr=" +
location.getPoint().latitude + "," + location.getPoint().longitude));
startActivity(intent);
While storing the lat and long store it in this way...
String mylocation=latitude + ":" + longitude;
And while retriving it
String latitude = mylocation.subString(0, myLocation.indexOf(":") - 1 );
String longitude = mylocation.subString(myLocation.indexOf(":"));
and pass it as
j.putExtra("lon", longitude);
j.putExtra("lat", latitude);
one possible way is to store your latitude
and longitude
values in shared preferences.
-To store values you can use
SharedPreferences sp = getSharedPreferences("MyPrefs", MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString("mytext", text);
editor.commit();
-and to retrive those values you can use
String value = prefs.getString("MyPrefs, "mytext");
in your code your are storing latitude and longitudes in double do not forget to convert them in toString()
...
hope this helps