我想通过距离获取我的位置顺序附近的所有机场。我正在使用附近的搜索请求谷歌地点使用此URL的API:https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=51.9143924,-0.1640153&sensor=true&key=api_key&radius=50000&types=airport我得到的结果是稀疏的,没有订单,所以永远。我尝试了rankby =距离但没有结果出现。 和https://developers.google.com/places/documentation/search#PlaceSearchRequests文档“如果rankby = distance,则不得包含半径”。如何使用附近的搜索请求按距离排序搜索结果
1
A
回答
0
不能使用radius
和rankby
在一起,这就是问题所在
1
是的,你不能在同一个请求使用半径和rankBy。但你可以使用rankBy=distance
然后根据geometry.location.lat
和geometry.location.lng
来计算你自己的距离。对于常规〔实施例我所做的那样:
GeoPosition
和Place
类都是由我来实现,所以不要指望在核心库:)找他们
TreeMap<Double, Place> nearbyPlaces = new TreeMap<Double, Place>()
if(isStatusOk(nearbySearchResponse))
nearbySearchResponse.results.each {
def location = it.geometry.location
String placeid = it.place_id
GeoPosition position = new GeoPosition(latitude: location.lat,
longitude: location.lng)
Place place = new Place(position)
double distance = distanceTo(place)
//If the place is actually in your radius (because Places API oftenly returns places far beyond your radius) then you add it to the TreeMap with distance to it as a key, and it will automatically sort it for you.
if((distance <= placeSearcher.Radius()))
nearbyPlaces.put(distance, place)
}
这里距离算如那个(Haversine公式):
public double distanceTo(GeoPosition anotherPos){
int EARTH_RADIUS_KM = 6371;
double lat1Rad = Math.toRadians(this.latitude);
double lat2Rad = Math.toRadians(anotherPos.latitude);
double deltaLonRad = Math.toRadians(anotherPos.longitude - this.longitude);
return 1000*Math.acos(
Math.sin(lat1Rad) * Math.sin(lat2Rad) +
Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad)
) * EARTH_RADIUS_KM;
}
相关问题
- 1. 按距离排序搜索结果
- 2. 如何根据距离排序搜索结果,使用textsearch搜索API位置
- 3. google附近的地方在“无效请求”中搜索结果
- 4. Facebook地点:按距离排列搜索结果
- 5. 基于距离的搜索和排序
- 6. SQL搜索按距离
- 7. FetchXML - GeoCode距离按距离搜索
- 8. 正在搜索“附近”结果
- 9. Symfony2,学说搜索和距离排序
- 10. 排序Lucene搜索结果
- 11. Hibernate搜索结果排序
- 12. 按meta_key排序搜索结果
- 13. wordpress按日期排序搜索结果
- 14. Rails的5:搜索按关键字和按距离排序
- 15. 如何重新排序搜索结果?
- 16. Google App Engine和Google Maps在Python中搜索近距离搜索
- 17. 搜索在距离
- 18. GeoDjango距离搜索
- 19. 搜索近似结果
- 20. 搜索和多个MYSQL请求排序
- 21. WordPress的距离搜索SQL
- 22. SQL Server的距离搜索
- 23. 搜索引擎的距离
- 24. VLV搜索请求:不可用关键扩展名:搜索结果无法排序,因为给定的搜索请求未编入索引
- 25. Bing自定义搜索 - 每个搜索结果附近的缩略图
- 26. 如何根据驾驶距离实时搜索结果?
- 27. 使用Solr,Sphinx或Lucene搜索 - 按点击排名的搜索结果
- 28. 的MongoDB:排序文本搜索结果
- 29. SQL搜索结果排名
- 30. Hibernate搜索结果排名