开发者

Bing Geocoding Help

开发者 https://www.devze.com 2023-02-24 22:52 出处:网络
I\'m trying to use Bing\'s REST api to geocode. But my \'y\' value is always null when I check my database. Any help would be appreciated.

I'm trying to use Bing's REST api to geocode. But my 'y' value is always null when I check my database. Any help would be appreciated.

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.Whit开发者_如何学PythonespaceHandling = 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
    {
    }
}


Does your location info contains a period (.), a comma (,), a colon (:) or a plus sign (+)? You should use the Unstructured URL syntax if this is the case. Info here:

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号