咨询HERE Discover API是否支持按距离对查询结果排序
Great question! Let's break this down for you:
Does the HERE Discover API support distance-based sorting?
Yes, it absolutely does! The default sorting for Discover results is based on relevance (which explains why your closest station landed in 4th place), but you can easily override this with the sort parameter.
To get results sorted by distance from your specified at coordinate (closest first), just add sort=distance to your query string. Here's your modified request example:
https://discover.search.hereapi.com/v1/discover?at=-34.0337365,151.0847004&q=station&limit=10&sort=distance&apikey=YOUR_API_KEY
This should push your nearest train station to the top of the results list immediately—no need to build a custom sorting solution from scratch.
Alternative Options
If for some edge case the sort=distance parameter doesn't behave as expected, you have a reliable fallback:
- Each result in the API response includes a
distancefield (measured in meters) that represents the exact distance from youratlocation. You could fetch the full results and sort them client-side using this value, though this is unnecessary if the built-in sorting works (which it should for most use cases). - For more targeted train station searches, you could also use the HERE Places API with a category filter for
train-stationinstead of a generalq=stationquery. This can boost result relevance while still working with thesort=distanceparameter.
内容的提问来源于stack exchange,提问作者misha

