Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用c#在坐标gps中转换csv文件中的地址,并更新此csv文件以包括纬度和经度_C#_Google Maps_Csv_Gps - Fatal编程技术网

使用c#在坐标gps中转换csv文件中的地址,并更新此csv文件以包括纬度和经度

使用c#在坐标gps中转换csv文件中的地址,并更新此csv文件以包括纬度和经度,c#,google-maps,csv,gps,C#,Google Maps,Csv,Gps,这是我的第一篇文章,我的代码有问题 我想使用csv文件的数据,提取c#中的地址,然后在这个csv文件中返回纬度和经度 这是我的csv文件: id;address;latitude;longitude; 01;paris;; 02;londres;; 04;madrid;; 05;berlin;; 我的代码是: static void Main(string[] args) { string line; CSV csv = n

这是我的第一篇文章,我的代码有问题

我想使用csv文件的数据,提取c#中的地址,然后在这个csv文件中返回纬度和经度

这是我的csv文件:

id;address;latitude;longitude;
01;paris;;
02;londres;;
04;madrid;;
05;berlin;;
我的代码是:

static void Main(string[] args) 

        {
            string line;

            CSV csv = new CSV();

            StreamReader reader =  new StreamReader(@"C:\Users\louis\Documents\coordonnee_gps\donnee.csv");
            var request = new GeocodingRequest();

            var adresse = "";
            string[] row = new string[5];
            while ((line = reader.ReadLine()) != null) 
            {
                if (adresse != null)
                {
                    request.Address = adresse;
                    request.Sensor = false;
                    var response = new GeocodingService().GetResponse(request);
                    var result = response.Results.First();
                    row[2] = "latitude" + result.Geometry.Location.Latitude;
                    row[3] = "longitude" + result.Geometry.Location.Longitude;
                }
            }

            csv.Save(new StreamWriter(@"C:\Users\louis\Documents\coordonnee_gps\donnee.csv"));
        }

首先关闭
StreamReader
以重新打开文件进行写入:


添加
reader.close()
csv.Save

之前运行此代码时会发生什么?您遇到了什么问题?当我运行此代码时,csv文件中没有任何更新,我出现以下错误:Une exception non gérée du type“System.InvalidOperationException”s's'est produite dans System.Core.dli在没有读卡器的情况下更新了csv文件。close(),但我在地址之前定义了,而不是在原始csv文件中拾取