0

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();
}
4

3 回答 3

1

使用 Tombstone Helper http://tombstonehelper.codeplex.com/

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
 {
this.SaveState(e);  // <- first line
 }

protected override void OnNavigatedTo(NavigationEventArgs e)
 {
this.RestoreState();  // <- second line
 }
于 2014-03-25T15:36:39.667 回答
1

您可以创建一些简单的东西,例如:

PhoneApplicationService.Current.State["latitude"] = MyGeoPosition.Latitude;
PhoneApplicationService.Current.State["longitude"] = MyGeoPosition.Longitude;

稍后访问它们:

var lat=PhoneApplicationService.Current.State["latitude"];
var lng=PhoneApplicationService.Current.State["longitude"];

您也可以尝试:

private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
appSettings.Add("latitude", MyGeoPosition.Latitude.ToString());
于 2014-03-25T15:41:42.193 回答
1

最简单的可定制方法是创建一个自定义对象并使用EZ_Iso.dll将其序列化到手机的存储中

这是一个例子

//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));

您可以在这里免费找到 EZ_Iso.dll http://anthonyrussell.info/postpage.php?name=2

于 2014-03-25T15:39:38.073 回答