【问题标题】:Bing Geocoding Help必应地理编码帮助
【发布时间】:2011-04-14 05:15:08
【问题描述】:

我正在尝试使用 Bing 的 REST api 进行地理编码。但是当我检查我的数据库时,我的 'y' 值始终为空。任何帮助将不胜感激。

private void Bing(geodata address)
{
    try
    {
        string query;
        //Create a new instance for holding geocoded data
        currentdata newaddress = new currentdata();
        newaddress.agency = address.agency;
        newaddress.calltime = address.calltime;
        newaddress.city = address.city;
        newaddress.state = address.state;
        newaddress.incidentType = address.incidentType;
        newaddress.intersection = address.intersection.Replace("&", "and");
        query = newaddress.intersection.ToString() + " " + newaddress.city.ToString() + " " + newaddress.state.ToString();
        // query = query.Replace("&", "and");
        //Geocoder returns data in XML format so we need to
        //create a new instance of XMLTextReader and provide an url
        XmlTextReader reader = new XmlTextReader
            ("http://dev.virtualearth.net/REST/v1/Locations/" + query + "?o=xml&key=MYBINGKEY");

        //Specify the way how white space is handled
        reader.WhitespaceHandling = WhitespaceHandling.Significant;

        //Start reading geocoded data
        while (reader.Read())
        {
            string node = reader.Name.ToString();  //current node in XML document
            string value = reader.ReadString();  //value/inner text of current XML node

            switch (node)
            {
                case "Name":
                    newaddress.intersection = value;
                    break;
                case "Latitude":
                    newaddress.y = double.Parse(value);
                    break;
                case "Longitude":
                    newaddress.x = double.Parse(value);
                    break;
                default:
                    continue;
            }
        }
        //Add geocoded address to our table
        cD.currentdatas.InsertOnSubmit(newaddress);
        cD.SubmitChanges();
    }
    catch
    {
    }
}

【问题讨论】:

    标签: c# geocode bing-api


    【解决方案1】:

    您的位置信息是否包含句点 (.)、逗号 (,)、冒号 (:) 或加号 (+)?如果是这种情况,您应该使用非结构化 URL 语法。信息here

    【讨论】:

    • 是否可以制作那个xml,我一直在获取json并且必须先保存文件
    • 谢谢,但这实际上不是问题。当我查看@ xml 时,我已经看到了经度和纬度。它只是没有迁移到我的对象。
    猜你喜欢
    • 2022-01-15
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多