Get WOEID from city name?
Asked Answered
O

4

6

I was using Google Weather API to fetch weather info, but apparently Google had stopped its service. And I am trying to switch to Yahoo Weather API now.

var WOEID = 2502265;  //random WOEID
$.ajax({
    url: "http://weather.yahooapis.com/forecastjson?w=" + WOEID + "&u=c",
    dataType: 'json',
    success: function(data) {
        console.log(data);
    }
});

However, is there a way that I can get the WOEID by JavaScript only? Because back then I can just do

http://www.google.com/ig/api?hl=en&weather=NYC

and that's it.

It says on the Yahoo weather API page,

To find your WOEID, browse or search for your city from the Weather home page. The WOEID is in the URL for the forecast page for that city. You can also get the WOEID by entering your zip code on the home page.

But I want to get it by JavaScript, not manually go to weather.yahoo.com and find out the WOEID.

Don't care about the Cross-Origin Policy because I am using it in an Chrome extension and it does not apply.

Olnton answered 15/9, 2012 at 4:48 Comment(0)
J
8

Okay I got to know from your comments what exactly you want

You have a place name and you want to get the WOEID of that place name using javascript ajax calls

The url to get that is not defined any where you have to use GeoPlanet service to resolve a place to a WOEID

http://where.yahooapis.com/v1/places.q('Place name')?appid=[yourappidhere] 

OR you have to use Direct YQL some what like this ( use percent encoding in the url for your city name ) appropriately and try doing an ajax call to this

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22Place%20name%22&format=xml
Jiles answered 15/9, 2012 at 5:21 Comment(2)
Sorry I pasted the wrong URL earlier the correct URL is in the answerJiles
A better way is to get data directly in json so that it can be handled more easily, by making format=json. Like- query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22Place%20name%22&format=jsonKorns
R
1

you can get it from yahoo too http://developer.yahoo.com/geo/geoplanet/guide/concepts.html

API Reference

Rideout answered 15/9, 2012 at 5:0 Comment(4)
Um, can you create an example or a few codes? Because I don't really know how to use its API...Akiko
Just use this URI where.yahooapis.com/v1/place/2507854?appid=[yourappidhere]Jiles
yes just the same way you have to do ajax call to that url and it will return the WOEID in JSON formatJiles
@aravind.udayashankara How do I use that URL while I don't have the WOEID?Akiko
N
0

DECEMBER 2018 UPDATE:

Definitely use the Direct YQL technique mentioned above by @aravind.udayashankara. I messed around with the yboss api for awhile only to see it has been discontinued (https://developer.yahoo.com/boss/search/) even though Yahoo still has plenty of documentation on it online.

Try the following instead (it runs off the page but there is code within the URL).

yourLocation = "location" (zip, city name, etc.)

urlQuery = "https://query.yahooapis.com/v1/public/yql?q=select+*+from+geo.places+where+text%3D%22" + yourLocation + "%22&format=json"
Negotiation answered 7/12, 2018 at 23:24 Comment(0)
A
-1

To get the Woeid by city name

using (WebClient wc = new WebClient())
{
string results = wc.DownloadString("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22" + CityName + "%22&format=xml");
}

See this article for more details

Agueda answered 19/4, 2017 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.