TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Efficient API to calculate distances?

2 点作者 RDDavies超过 14 年前
Google maps seems rather slow for this.<p>For ~200 displayed fields, need to calculate distance (by road) between a user-input zip and various other zips. Suggestions?<p>The project in question is finding autocross events within x miles of a user-entered zip, hence the need to do this dynamically, rather than store the data.

1 comment

byoung2超过 14 年前
You can trade some accuracy for speed by calculating the straight-line distance and then increasing it by some factor to account for turns and detours. Converting zip codes to latitude/longitude is a trivial process if you have a database (e.g. MaxMind) or API (e.g. SimpleGeo). You can calculate straight-line distance between two lat/lon pairs pretty easily (<a href="http://jan.ucc.nau.edu/~cvm/latlon_formula.html" rel="nofollow">http://jan.ucc.nau.edu/~cvm/latlon_formula.html</a>), and then pad this number to account for geography (e.g. 20 miles as the crow flies is ~27 miles driving).<p>If you can sacrifice even more accuracy, you can use 50-70 miles per degree latitude/longitude and just find results within a certain range of a given lat/lon pair.