我正在尝试编写一个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. 如何在python中获取城市(geonameid)的附近城市?
- 5. Google Places API自动填充特定城市
- 6. 根据Google Places API服务中的地点名称,城市名称和地址获取地点ID
- 7. iOS - 附近有Google Places API导出到数据库的附近地点
- 8. 如何使用Google Places API滚动地图时更新附近的地点?
- 9. Google Places API - 附近搜索(Ionic 2)
- 10. 如何获取使用Google Map API给出两个城市之间的地点
- 11. 如何使用Google Places API搜索特定类型的地点?
- 12. 获得来自谷歌Places API的城市的地方ID
- 13. Google地方/地图API获取subway_station城市列表
- 14. Google Places API中的城市级组件限制API
- 15. 地图API获取城市和国家
- 16. Google Places API地点描述
- 17. 使用Forecast API获取许多城市
- 18. 如何获取城市中的所有地标使用Google地图GeoCoding API?
- 19. 查找附近的大型城市GEONAMES
- 20. 从Google Places API获取地址信息
- 21. 如何到附近的景点或城市的兴趣地点,位置
- 22. 我可以使用Google API查找最近的城市吗?
- 23. 通过州和国家获取城市Google API
- 24. 使用Google Maps Api获取附近的所有餐厅,超市,商场等。
- 25. 城市附近城市Webservice或PHP代码
- 26. 如何使用Google地图API以lat,lng查找最近的城市
- 27. 在google地图中获取城市的地理栅栏
- 28. Google地图城市在该地区的城市
- 29. 是否可以在Google地图中获取城市A和城市B之间的城市列表
- 30. 将数据绑定到ListView以使用Google Places API和UWP显示到附近地点的距离
如果您觉得这个问题是重复的,请将其标记为这样。不要发布链接到其他堆栈溢出帖子作为答案。 – JAL
好吧,很高兴知道!我想如果我在任何地方发布我的答案,它可能会被标记为重复的答案......我将编辑答案并且不会链接到其他帖子√ – 0x1ad2