我正在尝试使用Google maps geocode API返回给定邮政编码的所有公园。似乎如果我有一个公园名称,我没有问题返回数据。如 http://maps.googleapis.com/maps/api/geocode/json?address=Kerry+Park+98122&sensor=false
但是,如果我搜索公园的邮政编码 http://maps.googleapis.com/maps/api/geocode/json?address=Parks+near+98122&sensor=false
我在地址中获得了parks
的邮政编码的任何结果。我尝试使用lanlng
,但这有同样的问题。谷歌似乎不允许types[]
查询结果,这是不幸的。
如果我在maps.google.com上搜索“98122附近的公园”,我会得到所有结果,但它似乎没有使用相同的API。
我要求Google maps Places api密钥,我认为这是我需要的。
我想我的问题是:
a)我在这里遗漏了什么吗?
b)我没有坚持使用谷歌API是他们的其他人将通过zip输出所有公园的JSON结果。我简短地看了Bing和雅虎都没有用。
感谢。
答案 0 :(得分:0)
Google地理编码器API没有在查询中指定“类型”(例如“park”)的规定。它将识别响应中的要素类型,但您无法将其放入请求中。
您可以在Google Places API中执行所需操作,现在可以进行开发人员预览。我没试过。您仍然无法在请求中指定类型,但您指定了位置和半径,并返回所有位置,并且每个位置都有一个或多个关联的类型代码(可能包括park)。您可以搜索返回的结果以查看是否显示公园。见http://code.google.com/apis/maps/documentation/places/
答案 1 :(得分:0)
使用Google Places API和文本搜索。
更改[zipcode]和密钥[apikey]:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=park+in+[zipcode]&key=[apikey]
答案 2 :(得分:0)
我刚刚进行了这项工作,我没有使用邮政编码,但是您可以获取邮政编码并获得经纬度对。此处已使用的经/纬对(地图中心设置)。
这是获取公园的查询。我会说这可能不是绝对的(仅主要公园),并且有20个限制。
这是来自他们的文档btw,使用Places api,此代码也来自ReactJS,因此参考例如。 “当前”
const plotParks = (parks) => {
// array of parks, use marker to plot on map and fit bounds to center
}
const service = new window.google.maps.places.PlacesService(mapTarget.current);
// radius in meters so I added mile to radius, seems correct, formula pulled from SO ha
const radiusInMeters = (Math.round(10000*(radiusMiles*5280 / 3.281))/10000);
service.nearbySearch(
{location: mapTarget.current.getCenter(), radius: radiusInMeters, type: ['park']},
(results, status, pagination) => {
if (status !== 'OK' || !results.length) {
alert('No parks found near you, try increasing your radius or try a new address');
} else {
plotParks(results);
}
});
对ctrl + f进行“存储”以跳转到代码 https://developers.google.com/maps/documentation/javascript/places