2012-10-02 4 views
0

며칠 전 올바르게 작동하는 csome 코드에 약간의 문제가 있습니다. 내가 '0으로 코드가 며칠 전에 잘 작동했지만 지금 logitude와 위도가 항상 반환 말했듯이C# .NET에서 Yahoo API를 사용하는 GeoCode

string url = string.Format("http://where.yahooapis.com/geocode?flags=J&appid=xxxx&location={0}", postcode); 

     decimal latitude = 0; 
     decimal longitude = 0; 
     Dictionary<string, decimal> geoCode = new Dictionary<string, decimal>(); 

     dynamic yahooResults = new Uri(url).GetDynamicJsonObject(); 
     foreach (var result in yahooResults.ResultSet.Results) 
     { 
      latitude = (decimal)result.latitude; 
      longitude = (decimal)result.longitude; 
     } 

     geoCode.Add("latitude", latitude); 
     geoCode.Add("longitude", longitude); 

     return geoCode; 

: 나는 코드가 아래와 같습니다 우편 번호에 대한 logitude와 위도를 얻을 수 Yahoos API를 사용하고 있습니다 아래에서 야후의 답변을 포함 시켰습니다.

{ 
    "@lang": "en-US", 
    "ResultSet": { 
    "@version": "2.0", 
    "@lang": "en-US", 
    "Error": "0", 
    "ErrorMessage": "No error", 
    "Locale": "en-US", 
    "Found": "1", 
    "Quality": "60", 
    "Result": { 
     "quality": "60", 
     "latitude": "51.62071", 
     "longitude": "-0.23616", 
     "offsetlat": "51.620708", 
     "offsetlon": "-0.23616", 
     "radius": "4200", 
     "name": "", 
     "line1": "", 
     "line2": "London", 
     "line3": "NW7", 
     "line4": "United Kingdom", 
     "house": "", 
     "street": "", 
     "xstreet": "", 
     "unittype": "", 
     "unit": "", 
     "postal": "NW7", 
     "neighborhood": "", 
     "city": "London", 
     "county": "Greater London", 
     "state": "England", 
     "country": "United Kingdom", 
     "countrycode": "GB", 
     "statecode": "ENG", 
     "countycode": "LND", 
     "uzip": "NW7", 
     "hash": "", 
     "woeid": "26787971", 
     "woetype": "11" 
    } 
    } 
} 

죄송합니다. 서식 지정을 원하지 않는 것으로 보입니다. 분명히 logitiude와 위도가 반환됩니다. 나는 이것이 단순한 것이라고 확신하지만 사랑이나 돈으로 볼 수는 없지만 어떤 도움을 주시면 감사하겠습니다.

답변

2

yahoo가 Result 배열을 더 이상 반환하지 않는 것 같습니다. 아래의 코드 작동

dynamic yahooResults =.....; 

var latitude = (decimal)yahooResults.ResultSet.Result.latitude; 
var longitude = (decimal)yahooResults.ResultSet.Result.longitude; 
+0

위대한 물건 LB는 대우를했습니다! –

+0

그들이 그것을 바꾼 것처럼 보입니다 ... – marcog