1
我在寫一個程序,需要保存一些座標(經度和緯度值)。 寫這些值似乎沒有問題,只是當我加載它們時,並將地圖圖釘應用到加載的座標。我的繼承人的代碼我使用負載:「...」的最佳過載匹配有一些無效參數
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, 雙)' 最好的重載的方法匹配具有一些無效參數
和
參數1:無法從 '字符串' 轉換爲 '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");
}
哪一行發生錯誤? – Ehsan
錯誤是顯而易見的,你傳遞的字符串,但它需要'GeoCoordinate'類型 –
我認爲最重要的是要明白爲什麼你會得到這個錯誤,並學習如何排除它的下一次。 – Jonesopolis