1

I have a very weird bug turn up in my code. I have a weather forecasting site I am building, it uses geolocation to find the city you reside in and then uses wunderground's API to give you the forecast. The problem is that when you search for a city manually using the search box, the forecast temperature returned in NAN, but when it uses your co-ordinates it returns correctly. I have no idea why this is happening.

I posted all the code up on JSBIN here : http://jsbin.com/agigeb/edit#javascript

I think it may have to do with how I extract the temperature from the string it is in (I don't use the integer temperatures it provides as it doesn't provide an integer temperature that changes based on the time of day, e.g. if it's the morning it returns the afternoon forecast and if it's the evening it returns the next morning's forecast)

That part is posted on this JSBIN here: http://jsbin.com/etupun/edit#javascript

Thank you in advance for any help, Jake.

Jake Champion
  • 57
  • 1
  • 8

1 Answers1

0

If you look at the JSON returned from these two requests, you can see what's going on:

http://api.wunderground.com/api/50ada0a5f0afbaec/geolookup/conditions/forecast/q/30301.json

http://api.wunderground.com/api/50ada0a5f0afbaec/geolookup/conditions/forecast/q/atlanta.json

The later query, using a text search string, returns an array of possible matches instead of a single forecast like the zip or lat/long search does.

You can use the "zmw" value from one of the items in that "results" array to retrieve the forecast for that single city.

Dave Ward
  • 59,815
  • 13
  • 117
  • 134
  • This is another problem I have found, I haven't got a clue on how to create an autocomplete like service on the search box that suggests the city you mean and then send the corresponding zmw in the query to wunderground. With this in mind though, when wunderground is sent a "correct" query which returns the full json required, it still parses it wrong and produces a NAN. her eis my website so you can see what I mean. http://jakechampion.de.nu If you search manually and type uk/oxford you will see it returns NAN for the forecast. – Jake Champion Jan 14 '12 at 07:12