I have a list of coordinates saved in a map class that are manipulated to draw a route between the points, but I'm not sure how to save these points when the application is closed and then reopened.
This is how I currently save the points within the app in the OnNavigatedTo()
, the points and markers aren't lost as long as I don't close it. But how do I save these coordinates after I close the app?
I'm guessing I should save them in the OnNavigatedFrom
but I tried saving the coordinate list here and the markers don't show when I repopen the app.
//save the coordinates to a list
mycoord.Add(new GeoCoordinate(MyGeoPosition.Latitude, MyGeoPosition.Longitude));
if (mycoord.Count == 2)
{
//call route method when coord list equal to two.
GetRoute();
}
The easiest way to do this that is customizable would be to create a custom object and serialize it to the phone's storage using EZ_Iso.dll
Here's an example
//Your custom GeoCoord container
[DataContractAttribute]
public class GeoCoordContainer{
[DataMember]
public double lat = 0;
[DataMember]
public double lon = 0;
public GeoCoordContainer(Double lat, Double lon){
this.lat = lat;
this.lon = lon;
}
}
//Then in your Navigated from method
GeoCoordContainer cont = new GeoCoordContainer(MyGeoPosition.Lattitude,MyGeoPosition.Longitued);
//Now save it to the storage using EZ_Iso
EZ_Iso.IsolatedStorageAccess.SaveFile("MyLocation",cont);
//To Retrieve it from storage
GeoCoordContainer cont = (GeoCoordContainer)EZ_Iso.IsolatedStorageAccess.GetFile("MyLocation",typeof(GeoCoordContainer));
You can find EZ_Iso.dll free here http://anthonyrussell.info/postpage.php?name=2