Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get local weather with only client-side script

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.

like image 247
Waqar Ahmed Avatar asked Nov 05 '22 08:11

Waqar Ahmed


1 Answers

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);
    }
});
like image 102
Peter-Paul van Gemerden Avatar answered Nov 15 '22 01:11

Peter-Paul van Gemerden