Search code examples
rubydatabasegeolocation

Offline Geo calculations using Ruby, can they be done?


I'm new to GeoCoding/GeoData/etc, and have a question about making calculations without connecting to an online Geo service.

If already know the longitude and latitude for x, and the longitude and latitude for y, is it possible to determine the distance between the two points without accessing an online service (ie Google, Geocoder.ca, etc)?

Currently the data is in a MySQL database.

Note: I have found a couple of semi-related answers here, but they link to C libraries, while I'm using Ruby.

UPDATE: Just in case you are already using RubyGeocoder for online service enquiries, you may be interested to know that it has the Haversine function built-in, documented here.


Solution

  • The distance between to points can be calculated using the Haversine formula. (Wikipedia: http://en.wikipedia.org/wiki/Haversine_formula)

    Here is an example implementation: http://www.esawdust.com/blog/gps/files/HaversineFormulaInRuby.html