我正在编写一个需要保存一些坐标(纬度和经度值)的程序。 写这些值似乎不是问题,只是在我加载它们时,并将地图图钉应用于加载的坐标。继承我正在使用的代码:
try
{
//Read the file from the specified location.
fileReader = new StreamReader(new IsolatedStorageFileStream("cords.txt", FileMode.Open, fileStorage));
//Read the contents of the file (the only line we created).
string cords = fileReader.ReadToEnd();
Pushpin car = new Pushpin();
car.Background = new SolidColorBrush(Colors.Green);
car.Foreground = new SolidColorBrush(Colors.Black);
car.Content = "You Parked Here";
car.Tag = "carPushpin";
car.Location = cords; //getting error here...
this.map.Children.Add(car);
this.map.SetView(cords, 18.0); // ...and here
//Write the contents of the file to the TextBlock on the page.
fileReader.Close();
}
catch
{
MessageBox.Show("Debug Errror-no cords.txt");
}
和我得到的错误:
无法隐式转换类型'string' 'System.Device.Location.GeoCoordinate'
最佳重载方法匹配 “Microsoft.Phone.Controls.Maps.Core.MapBase.SetView(System.Device.Location.GeoCoordinate, double)'有一些无效的参数
和
参数1:无法从'string'转换为 'System.Device.Location.GeoCoordinate'
希望你们能帮帮我
我已尽最大努力编辑了我的代码,但仍然无法解决问题... 编辑过的代码:
try
{
//Read the file from the specified location.
fileReader = new StreamReader(new IsolatedStorageFileStream("latitude.txt", FileMode.Open, fileStorage));
//Read the contents of the file (the only line we created).
string carlatitude = fileReader.ReadToEnd();
fileReader = new StreamReader(new IsolatedStorageFileStream("longitude.txt", FileMode.Open, fileStorage));
//Read the contents of the file (the only line we created).
string carlongitude = fileReader.ReadToEnd();
fileReader.Close();
carlocation = new GeoCoordinate(carlatitude, carlongitude);
Pushpin car = new Pushpin();
car.Background = new SolidColorBrush(Colors.Green);
car.Foreground = new SolidColorBrush(Colors.Black);
car.Content = "You Parked Here";
car.Tag = "carPushpin";
car.Location = carlocation;
this.map.Children.Add(car);
this.map.SetView(watcher.Position.Location, 18.0);
}
catch
{
MessageBox.Show("Debug Errror-no cords.txt");
}
答案 0 :(得分:4)
您需要将coords
的字符串表示形式转换为System.Device.Location.GeoCoordinate
并将其传递给SetView方法。