如何将坐标列表保存到独立存储? [英] How to save a list of coordinates to isolated storage?
问题描述
我有一个地理坐标列表,我想在应用程序关闭时将其保存到存储中,但我不确定如何将其保存到存储中.
I have a GeoCoordinate list that I want to save to storage when the application is closed, but I'm not sure how to save it to storage.
我尝试使用此处找到的帮助程序类保存列表 在独立存储中存储对象列表的问题 但我认为我的语法可能是错误的,因为我不熟悉使用列表.这就是我尝试保存列表的方式.任何人都可以通过保存点亮来为我指明正确的方向吗?
I tried saving the list using a helper class found here problem Storing a list of Objects in Isolated Storage but I think my syntax may be wrong in saving it as I'm new to using lists.This is how I tried to save the list. Can anyone point me in the right direction with saving the lit?
mycoord = Isolated_Storage_Helper.IsoStoreHelper
.SaveList<mycoord>("Storage_Folder/", "Storage");
它给了我一个错误,指出 mycoord 是一个字段,但用作类型
It gives me an error stating that mycoord is a field but is used as a type
mycoord
是在全局级别创建的坐标列表:
mycoord
is a list of coordinates created at a global level:
List
并填充到 OnNavigatedTo 方法中:
And populated in the OnNavigatedTo method:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (NavigationContext.QueryString.ContainsKey("GeoLat") &&
NavigationContext.QueryString.ContainsKey("GeoLong") &&
NavigationContext.QueryString.ContainsKey("pName"))
{
if (mycoord.Count >= 2)
{
//do something,draw route between points
return;
}
else
{
var latitude = Convert.ToDouble(NavigationContext.QueryString["GeoLat"]);
var longtitude = Convert.ToDouble(NavigationContext.QueryString["GeoLong"]);
var MyGeoPosition = new GeoCoordinate(latitude, longtitude);
var pushPinName = NavigationContext.QueryString["pName"];
DrawPushPin(MyGeoPosition, pushPinName);
mycoord.Add(MyGeoPosition);
}
}
base.OnNavigatedTo(e);
}
推荐答案
首先创建坐标类:
[DataContract]
class coord{
[DataMember]
public double lat{get;set;}
[DataMember]
public double lon{get;set;}
}
现在如果你想保存一个List
你可以这样做:
Now if you want to save a List<coord>
You may do:
DataContractSerializer ser = new DataContractSerializer(typeof(List<coord>));
ser.WriteObject(any_file_stream, instance_of_List<coord>);
但是如果你只想保存几个坐标,而不是一个列表 IsolatedStorageSetting 会是更好的选择.
But if you want to save just a couple of coordinates, not a list IsolatedStorageSetting would be a better option.
这篇关于如何将坐标列表保存到独立存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!