2011-04-14 3 views
0

빙의 REST API를 사용하여 지오 코딩을 시도하고 있습니다. 하지만 내 'y'값은 항상 데이터베이스를 검사 할 때 null입니다. 어떤 도움을 주시면 감사하겠습니다.빙 지오 코딩 도움말

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

위치 정보에 마침표 (.), 쉼표 (,), 콜론 (:) 또는 더하기 기호 (+)가 포함되어 있습니까? 이 경우 Unstructured URL 구문을 사용해야합니다. 정보 here :

+0

xml을 만들 수 있으며, 계속 json을 얻고 파일을 먼저 저장해야합니다. –

+0

@Antarr 'o = xml'을 추가하십시오. – jfs

+0

고마워,하지만 사실은 문제가 아니야. @ xml을 보면 이미 경도와 위도가 모두 표시됩니다. 단지 내 개체로 마이그레이션되지 않습니다. –