我正在尝试编写一个Java应用程序,该应用程序给定城市和半径,返回所有附近的城市。我认为Google Maps API能够做到这一点,但我没有使用Places API,只是返回感兴趣的点(例如餐馆,...)。有没有这样做的方式与谷歌API或有一些其他的API(或这样做),你会建议?使用Google Places API在特定地点获取附近城市
7
A
回答
2
您很可能不想使用Places API。您可能想查看是否有方法使用地理编码/反向地理编码来获得您想要的内容。见http://code.google.com/apis/maps/documentation/geocoding/。
根据您的性能和准确性要求,您可能无法使用Google Maps API(或任何其他免费工具)轻松做到这一点(特别是全球范围内),但您可能可以获得某种主要类型的东西 - 作品,特别是如果你有地理限制(例如,只是美国),可能会简化事情。
3
我写的代码片段,您可以通过组合谷歌地图API地理编码检索附近的所有城市和GeoNames.org API(除了一个的file_get_contents你也可以做一个卷曲请求)。
/*
* Get cities based on city name and radius in KM
*/
// get geocode object as array from The Google Maps Geocoding API
$geocodeObject = json_decode(file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address={CITY NAME},{COUNTRY CODE}'), true);
// get latitude and longitude from geocode object
$latitude = $geocodeObject['results'][0]['geometry']['location']['lat'];
$longitude = $geocodeObject['results'][0]['geometry']['location']['lng'];
// set request options
$responseStyle = 'short'; // the length of the response
$citySize = 'cities15000'; // the minimal number of citizens a city must have
$radius = 30; // the radius in KM
$maxRows = 30; // the maximum number of rows to retrieve
$username = '{YOUR USERNAME}'; // the username of your GeoNames account
// get nearby cities based on range as array from The GeoNames API
$nearbyCities = json_decode(file_get_contents('http://api.geonames.org/findNearbyPlaceNameJSON?lat='.$latitude.'&lng='.$longitude.'&style='.$responseStyle.'&cities='.$citySize.'&radius='.$radius.'&maxRows='.$maxRows.'&username='.$username, true));
// foreach nearby city get city details
foreach($nearbyCities->geonames as $cityDetails)
{
// do something per nearby city
}
要小心您的要求量,因为API的有限
对API的访问欲了解更多信息,以下网址:
相关问题
- 1. Google Places Autocomplete Web Api,获取特定城市的区域
- 2. 如何从特定的城市获取附近的城市?
- 3. 从Google Places API获取附近地点列表(Swift 3)
- 4. 如何从Google Places API获取城市景点图像
- 5. 如何使用Google Places API获取特定类型的地点?
- 6. 如何在特定城市使用谷歌地点API在PHP
- 7. 如何在python中获取城市(geonameid)的附近城市?
- 8. 使用Google Maps API的最近城市
- 9. Google Places JS API,特定城市的街道名称
- 10. Google Places API自动填充特定城市
- 11. 如何使用Google地图API获取郊区的父城市?
- 12. 根据Google Places API服务中的地点名称,城市名称和地址获取地点ID
- 13. 如何在ios中获取地理位置附近的城市或州名?
- 14. iOS - 附近有Google Places API导出到数据库的附近地点
- 15. 如何使用Google Places API在一个城市或国家/地区获取所有地点(或餐馆等特定类型的地点)?
- 16. 如何使用Google Places API滚动地图时更新附近的地点?
- 17. 使用Google Places api查找附近的地方
- 18. Google地图/ Places API - 在用户点击时获取地址place_id?
- 19. 如何使用Google地图获取附近的地点?
- 20. 如何获取使用Google Map API给出两个城市之间的地点
- 21. Google Places API - 附近搜索(Ionic 2)
- 22. 获取城市周围的城市与谷歌地点api给定半径城市的列表
- 23. 如何使用Google Places API搜索特定类型的地点?
- 24. 查找距离特定地点最近的城市
- 25. 使用Google API获取城市的国家/国家建议
- 26. 获得来自谷歌Places API的城市的地方ID
- 27. Google地方/地图API获取subway_station城市列表
- 28. 使用Google Places API获取地点列表
- 29. 如何获取Google Places API的地方网站和照片附近的搜索
- 30. 地图API获取城市和国家
如果您觉得这个问题是重复的,请将其标记为这样。不要发布链接到其他堆栈溢出帖子作为答案。 – JAL
好吧,很高兴知道!我想如果我在任何地方发布我的答案,它可能会被标记为重复的答案......我将编辑答案并且不会链接到其他帖子√ – 0x1ad2