【发布时间】:2012-05-23 07:32:45
【问题描述】:
如果我使用YQL知道城市的经纬度,如何获取城市的WOEID?
【问题讨论】:
如果我使用YQL知道城市的经纬度,如何获取城市的WOEID?
【问题讨论】:
对于那些仍在尝试通过坐标查找 WOEID 的人,其他答案现在已经过时了。使用geo.placefinder数据表查询经纬度,返回结果中会出现WOEID。
通过 YQL:
SELECT * FROM geo.placefinder WHERE text="{$seedLat}, {$seedLon}" and gflags="R"
(Test it out on the YQL Console.)
通过 REST:
http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20geo.placefinder%20WHERE%20text%3D%22{$seedLat}%2C{$seedLon}%22%20and%20gflags%3D%22R%22
【讨论】:
Tenant 'query_yahooapis_com' access to 'Resource [tenantName=query_yahooapis_com, type=TABLE, name=geo.placefinder, locatorType=FILE, url=/home/y/share/manhattan/application/tenantBundles/yql_query_yahooapis_com_manhattan_v2/YQL-INF/restdefs/geo.placefinder.xml, useUrl=false]' is denied.
可以参考官方网页: http://developer.yahoo.com/boss/geo/docs/free_YQL.html
这是一个例子: select * from geo.placefinder where text="37.416275,-122.025092" and gflags="R"
【讨论】:
看起来 Yahoo 已将 geo.placefinder 表设为非公开,这意味着访问需要有效的应用程序 ID 和 OAuth 身份验证(请参阅 Free Non-Commercial YQL Table Usage)。如果您只需要 WOEID 并且您知道城市和州,则可以改用 geo.places 表:
select * from geo.places where text="Hanover, PA" AND placeTypeName.code = 7
如果找到结果,WOEID 将返回为data.query.results.place.woeid。
但是,这并不完美。在宾夕法尼亚州,我们(至少)在搜索“汉诺威”时会出现三个地方(约克县的汉诺威、比弗县的汉诺威镇和卢塞恩县的汉诺威镇)。在使用此方法进行搜索时,这可能会也可能不会影响您的结果。使用邮政编码应该会提高结果的准确性,并且可以使用boundingBox 属性按已知纬度/经度过滤结果:
select * from geo.places where text="Eagle, Wisconsin" AND
boundingBox.southWest.latitude <= 42.9147280 AND
boundingBox.southWest.longitude <= -88.4426340 AND
boundingBox.northEast.latitude >= 42.9147280 AND
boundingBox.northEast.longitude >= -88.4426340 AND
placeTypeName.code = 7
您仍然需要提供几个必需的密钥之一(text 是一个有效的必需密钥),因此这不符合仅按地理坐标搜索的条件,但希望这算得上次优。
【讨论】:
使用 YQL 控制台,您可以搜索“placeTypeName.code”为 7 的最近地点
http://developer.yahoo.com/yql/console/
SELECT * FROM geo.places WHERE text="{$seedLat}, {$seedLong}" AND placeTypeName.code = 7
此查询的 REST 查询类似于:
http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20geo.places%20WHERE%20text%3D%22{$seedLat}%2C%20{$seedLong}%22%20AND%20placeTypeName.code%20%3D%207&format=json&diagnostics=true&callback=
显然用您自己的坐标替换 $seedLat 和 $seedLong :)
【讨论】:
以前的答案都不再有效,但现在有效。
您需要在查询中组合闪烁表,如下所示:
select place.woeid from flickr.places where lat="" and lon="" and api_key=""
从 Flickr 获取 API KEY 是即时的: https://www.flickr.com/services/apps/create/
【讨论】: