从API获取经度和纬度

时间:2020-02-12 11:31:17

标签: c# ssis bing-api

我已经在google上和堆栈中进行了搜索,但是由于我在C#和SSIS方面的专业知识有限,因此在通过时遇到了一些麻烦。

我在此SSIS软件包中的步骤如下,

1)我有一个与for循环连接的SQL任务,仅指定我应在= 1的Foorloop容器中迭代多少次

2)在Foorloop容器内部有一个数据流任务

3)在数据流任务中,我使用OLEDB源从SQL表获取地址

4)我将OLEDB源连接到一个脚本任务,以下脚本“应该”从中返回我的XML答案,我想从中返回纬度和经度。它不会返回我想要的答案。

示例地址为-Beihinger Strasse 160 DE-71726 BENNINGEN GERMANY

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    string url = "http://dev.virtualearth.net/REST/v1/Locations?addressLine={0}&output=xml&key={1}";
    var Address = Row.Address;
    var wGet = WebRequest.Create(String.Format(url, Address, Variables.APIkey));
    wGet.Method = WebRequestMethods.Http.Get;
    var response = wGet.GetResponse();
    var status = ((HttpWebResponse)response).StatusDescription;
    Console.WriteLine("Input: " + Address);



    if (status == "OK")
    {
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string responseFromServer = reader.ReadToEnd();
        reader.Close();

        var xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(responseFromServer);
        var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
        nsmgr.AddNamespace("Point", "http://schemas.microsoft.com/search/local/ws/rest/v1");
        var latNode = xmlDoc.DocumentElement.SelectSingleNode("/ResourceSets/ResourceSet/Resources/Location/Point/Latitude", nsmgr);
        var lngNode = xmlDoc.DocumentElement.SelectSingleNode("/ResourceSets/ResourceSet/Resources/Location/Point/Longitude", nsmgr);


        if (latNode != null && lngNode != null)
        {
            var numberFormatInfo = new NumberFormatInfo { NumberDecimalSeparator = "." };
            Row.Latitude = decimal.Parse(latNode.InnerText, numberFormatInfo);
            Row.Longitude = decimal.Parse(lngNode.InnerText, numberFormatInfo);
            Row.FullResponse = responseFromServer.ToString();

        }
        else
        {
            //Set to null
            Row.Latitude_IsNull = true;
            Row.Longitude_IsNull = true;
            Row.FullResponse = responseFromServer.ToString();

        }
    }
    else
    {
        //Set to null
        Row.Latitude_IsNull = true;
        Row.Longitude_IsNull = true;
        Row.FullResponse_IsNull = true;

    }


    response.Close();
}

}

我得到的答复是

版权所有©2020 Microsoft及其供应商。版权所有。未经Microsoft Corporation明确书面许可,无法访问此API,并且不得以任何方式使用,复制或传输内容和任何结果。http://dev.virtualearth.net/Branding/logo_powered_by.png 200OKValidCredentialsb9a94b411dc246ea82d161dae5e7a0c3 | DU00000D73 | 0.0.0.1 | Ref A:ACDD23537F6649F6B2F66333BB6D6 DB3EDGE0918参考C:2020-02-12T11:25:05Z0

我想使用URL时获得正确的通话,以便获得经度和纬度-http://dev.virtualearth.net/REST/v1/Locations?addressLine=Beihinger%20Strasse%20160%20DE-71726%20BENNINGEN%20GERMANY&output=xml&key= {APIkey}

对我所缺少的任何帮助将不胜感激?

0 个答案:

没有答案