Get local weather only from the client side of the script

I am creating a JavaScript application that shows the weather of several places. Using the Yahoo Weather API, I easily retrieve data for multiple locations by manually providing a WOEID. However, I also want to get a weather forecast for the user's current location. Using the GeoLocation API, I can get the user's city name; however, Yahoo only works with its WOEID (area codes).

Can someone guide me about the approach that I have to take in order to get the user's local weather only from the client side of the script?

Note. I do not want the user to enter / search the name of their city, I want to show it directly when it loads the page.

+4
source share
1 answer

It should be possible to use 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); } }); 
+2
source

Source: https://habr.com/ru/post/1388282/


All Articles