TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Calculate Latitude/Longitude Distances in MySQL with the Haversine Function

16 pointsby heyjonboyover 14 years ago

7 comments

thibaut_barrereover 14 years ago
Anecdote on Haversine: in 1.6, MongoDB's built-in "geonear" was using non-spherical indexing, but I needed to get more accurate results in a project, so I queried 3 times more records and used Haversine afterward to sort records again, client-side. Here's the ruby code:<p><a href="http://gist.github.com/559482" rel="nofollow">http://gist.github.com/559482</a><p>Since then, MongoDB 1.7 has been released with spherical sort support (<a href="http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-TheEarthisRoundbutMapsareFlat" rel="nofollow">http://www.mongodb.org/display/DOCS/Geospatial+Indexing#Geos...</a>)
bravo_sierraover 14 years ago
Why in the world would you use this when MySQL has almost proper geospatial support? It's far more efficient and less incorrect.<p>I swear - next time I'm going to get a R-Tree novelty account.
评论 #1841946 未加载
评论 #1842197 未加载
akharrisover 14 years ago
One of those things you never think about when reading a map or driving in a car, but it's the explanation behind why you fly all the way up past nova scotia when on a plane to europe.
philfreoover 14 years ago
Sphinx (<a href="http://sphinxsearch.com/" rel="nofollow">http://sphinxsearch.com/</a>) is really good at geo/spatial searches on MySQL data<p>Example: <a href="http://www.god-object.com/2009/10/20/geospatial-search-using-sphinx-search-and-php/" rel="nofollow">http://www.god-object.com/2009/10/20/geospatial-search-using...</a>
评论 #1842210 未加载
wazooxover 14 years ago
&#60;rant&#62;I've got a better idea: use postgis and get rid of mysql and its quirks.<p>Yep, I just reinstalled an old app yesterday, and for some unfathomable reason it loses communication with mysql at some point (it worked perfectly for what, 6 years?). Gosh, I hate mysql.&#60;/rant&#62;
评论 #1842207 未加载
ljegouover 14 years ago
Beware, coordinates are not always expressed in the same referencial (geoid, ellipsoid, etc.).
lzimmover 14 years ago
wont that completely negate the value of the indices that lat/lon may/may not sit on and result in a complete tablescan?
评论 #1841866 未加载
评论 #1841948 未加载
评论 #1842191 未加载