5

I am making a JavaScript app which shows the weather of several places. Using the Yahoo Weather API, I easily get the data for several locations by manually giving WOEID. However I also want to get the weather of the current location of the user. Using the GeoLocation API, I can get the city name of the user; however Yahoo only works with its WOEID (city codes).

Can anyone guide me about the sort of approach I should take to get local weather of the user with only client-side script?

Note: I don’t want the user to enter/search their city name, I want to show it directly when theyloads the page.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Waqar Ahmed
  • 258
  • 1
  • 5
  • 16
  • Try using Yahoo! PlaceFinderAPI (http://developer.yahoo.com/geo/placefinder/) – Zain Khan Dec 28 '11 at 11:49
  • According to the documentation "PlaceFinder recognizes a large number of place formats and returns rich geographic data about each result, including geographic coordinates, address components, and **WOEID**." – Zain Khan Dec 28 '11 at 11:50
  • 1
    Edit your questions and add the code that you have written so far. How do you get the weather through WOEID and how do you retrieve the city name with Geolocation API. Without demonstrating what you have done so far, you won't get much help. – Abbas Dec 28 '11 at 11:53
  • Thanks mangobug, I'll have a look into that aswell – Waqar Ahmed Dec 28 '11 at 12:11

1 Answers1

2

It should be possible using this YQL Geo Library. This should work:

yqlgeo.get('visitor', function(o) {
    if (o.error) {
        alert('Unable to determine user location');
    } else {
        alert('WOEID: ' + o.place.woeid);
    }
});