2011-04-14 59 views
0

我正在嘗試使用Bing的REST api來進行地理編碼。但是當我檢查我的數據庫時,我的'y'值總是爲空。任何幫助,將不勝感激。Bing地理編碼幫助

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 
    { 
    } 
} 

回答

1

您的位置信息是否包含句點(。),逗號(,),冒號(:)或加號(+)?如果是這種情況,您應該使用非結構化URL語法。信息here

+0

是否有可能使該XML,我不斷得到JSON,並必須先保存該文件 – 2011-04-14 05:52:46

+0

@Aararr添加'O = Xml'。 – jfs 2011-04-14 06:21:18

+0

謝謝,但那實際上不是問題。當我看@的XML我已經得到經度和緯度出現。它只是不會遷移到我的對象。 – 2011-04-14 15:15:30