Gus Shortz
Gus Shortz

Reputation: 1771

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.

Upvotes: 2

Views: 143

Answers (2)

Weihang Jian
Weihang Jian

Reputation: 8755

Since our Earth is an ellipsoid instead of a sphere, If you are looking for a more accurate solution, take a look at Lambert's formula.

I've made an implementation for this.

https://github.com/tonytonyjan/geodesics

It Passes a test set of 500,000 geodesics for the WGS84 ellipsoid with more than 99% accuracy.

Upvotes: 0

dwo
dwo

Reputation: 3636

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

Upvotes: 2

Related Questions