c# - "..."的最佳重载匹配有一些无效参数

标签 c# windows-phone-8 bing-maps isolatedstorage

我正在编写一个需要保存一些坐标(纬度和经度值)的程序。 写入这些值似乎不是问题,只是当我加载它们并将 map 图钉应用于加载的坐标时。这是我用来加载的代码:

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

以及我遇到的错误:

Cannot implicitly convert type 'string' to 'System.Device.Location.GeoCoordinate'

The best overloaded method match for 'Microsoft.Phone.Controls.Maps.Core.MapBase.SetView(System.Device.Location.GeoCoordinate, double)' has some invalid arguments

Argument 1: cannot convert from 'string' to '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");
        }

最佳答案

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

关于c# - "..."的最佳重载匹配有一些无效参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17889843/

相关文章:

javascript - 如何在 bing map 信息框中创建按​​钮?

javascript - 使用来自数据库的位置坐标在 Bing map 上实现 pointInpolygon 搜索算法

c# - 使用 ImmutableSortedSet<T> 进行线程安全缓存

c# - Entity Framework 中的双重自引用

c# - 使用 FTP 协议(protocol)列出包含大约 2,000,000 个文件的目录

c# - 在 C# 中动态创建的用户控件

c# - Windows Phone 8 上的 VariableSizedWrapGrid

c# - 使用 C# 通过代码固定应用程序时,在应用程序列表页面上停用 ' pin to start '?

.net - 嵌入式 WebBrowser 控件拦截水平滚动事件

c# - 如何在 Windows Phone 7 中的 bing map 中从 ViewModel 设置经度和纬度