API based on geo infos issue

  • 1
  • Problem
  • Updated 2 years ago
Hello,

I'm using Google Maps Place API restricted to cities research, whence 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:

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, 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?

Can you help me, please?


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

Davide R

  • 3 Posts
  • 0 Reply Likes
  • puzzled

Posted 2 years ago

  • 1
Photo of Brendan Hayes

Brendan Hayes, Official Rep

  • 962 Posts
  • 123 Reply Likes
Locations outside the US don't take in /state/  
Photo of Davide R

Davide R

  • 3 Posts
  • 0 Reply Likes
Well Brendan, it's not clear to me.
What if the city name i'm searching for is available more than one time? What can I do in this case?

I mean, if I make this call:

http://api.wunderground.com/api/{KEY}...

I'll get the not found error, of course.
(Edited)
Photo of Brendan Hayes

Brendan Hayes, Official Rep

  • 962 Posts
  • 123 Reply Likes
When there is an ambiguous search the result has a "l" variable that you can use to link to the singular city result.  That way when there's more than 1 city, you know where to go next.  Or use lat/lon searches, that works too.   http://api.wunderground.com/api/KEY/conditions/q/new_delhi.json
Photo of Davide R

Davide R

  • 3 Posts
  • 0 Reply Likes
Perfect Brendan, thank you for your help.

I'm using the API through lat/lon search to ensure the right response for every city in the world and it works like a charm. :)

Thank you again.

Davide