Search code examples
jsonapigoogle-places-apigeowunderground

Wunderground API - country/state/city mix issue


I'm using Google Maps Place API restricted to cities research, hence I get city, state and country plus conditions and forecast10day Wunderground API.

It seems sometimes I've issues building the Wunderground API endpoint.

When I have a city available in just one country, I've this endpoint:

http://api.wunderground.com/api/{KEY}/conditions/q/IT/Milan.json

and it works like a charm.

When I know the city I'm searching for is available in many countries, I add the "state" value to the endpoint, like this:

http://api.wunderground.com/api/{KEY}/conditions/q/US/PA/Lancaster.json

The issue comes when I search for New Delhi in India (and at this point I'm afraid also for other cities):

http:// api.wunderground.com/api/{KEY}/conditions/q/IN/DL/NewDelhi.json

In this case the response is this:

"error": {
    "type": "querynotfound",
    "description": "No cities match your search query"
}

But If I call conditions/ for New Delhi in India via "zmw" parameter

http://api.wunderground.com/api/{KEY}/conditions/q/zmw:00000.1.42182.json

I see this in "display_location" object:

"city":"New Delhi / Safdarjung",
"state":"DL",
"state_name":"India",
"country":"IN"

So, it seems that formally my endpoint is right. What am I going wrong in?

PS: I'm using Google Maps Place API 'cause it's also UI ready. :)


Solution

  • I've contacted the Wunderground tech support.

    Well - as they told me - their API is a little bit inconsistent, so for places outside of US, the best solution is to make an API call via lat/lng values, so to ensure always the same response structure.

    For me it has been possible 'cause via Google Maps Places I save also lat/lng values for the city I'm searching for.

    So, you can build this endpoint:

    https://api.wunderground.com/api/{KEY}/conditions/q/{lat},{lng}.json

    and it works like a charm!