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

1 回答 1

4

您需要将您的字符串表示形式coords转换为 aSystem.Device.Location.GeoCoordinate并将其传递给 SetView 方法。

于 2013-07-26T19:53:39.997 回答