【发布时间】:2013-07-27 05:23:27
【问题描述】:
我正在编写一个需要保存一些坐标(纬度和经度值)的程序。 写入这些值似乎不是问题,就在我加载它们并将地图图钉应用于加载的坐标时。这是我用来加载的代码:
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");
}
以及我得到的错误:
无法将类型“字符串”隐式转换为 '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");
}
【问题讨论】:
-
哪一行出错了?
-
错误很明显,你传递的是字符串但它需要
GeoCoordinate类型 -
我认为最重要的是了解您收到该错误的原因,并学习如何在下次解决它。
-
只需要把this.map.SetView(watcher.Position.Location, 18.0)改成this.map.SetView(carlocation, 18.0)?从您的代码 sn-p 中,我们不知道 watcher.Position.Location 是什么。
标签: c# windows-phone-8 bing-maps isolatedstorage