php - Find out if Yahoo Weather data exist from where.yahooapis response

939

I am creating a weather page in PHP.

The user enters a city/place name in a search form and I search for his input in where.yahooapis to find the 5 top relative woeids.

(i.e. http:// where.yahooapis.com/v1/places.q("Rethimno");start=0;count=5?appid=...)

Then I present the 5 top relatives results in a radio button list. The user selects a city/place from the list and I fetch the weather data for his choice from weather.yahooapis.

(i.e. http:// weather.yahooapis.com/forecastrss?w=961110)

I noticed that there are woeids with “placeTypeName” code="7" (i.e. Town) for which there are no weather data. (i.e. 961110)

Is there a way to know if weather data exists for a place from the where.yahooapis response, so that I don't include it in the radio button list, or the only way to know that is by doing a http request to weather.yahooapis and parse the response for an error?

(i.e. < title /> Yahoo! Weather – Error … )

347

Answer

Solution:

I think there is no other way to do it without sending the http request. The other option is the check all the 5 cities before displaying them but I know this is not a very good solution.

But I think it makes sense to display "No Weather data for this location" than not displaying the location.

I had a similar situation for an intranet widget. I used to manually check and remove places which had no weather data (from a predefined list of cities) But the users wanted me to add it because when they don't find the city name in the widget, the next thing they do it check Yahoo's weather site (or weather.com) which does not have weather data. So to prevent this extra effort by the user I had to add the city to the list.

People are also looking for solutions to the problem: Using PHP and google Maps Api to work out distance between 2 post codes (UK)

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.