Computes the bounding coordinates of all points on the surface of a sphere that have a great circle distance to the given point. This code was ported to ruby directly from http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates, and is owned by Jan Philip Matuschek.
Add this line to your application's Gemfile:
gem 'jpm_geo'
And then execute:
$ bundle
Or install it yourself as:
$ gem install jpm_geo
# use miles as a distance unit (default is kilometers)
JpmGeo.units = 'm'
# specify default radius (default is Earth kilometers)
JpmGeo.radius = 3389.5 # Mars radius (km)
# lonlat is an object that responds to 'lon' and 'lat' methods
point = JpmGeo::Point.from_lonlat(lonlat)
# from degrees
point = JpmGeo::Point.from_degrees(lat: 51.50853, lon: -0.12574) # London
# from radians
point = JpmGeo::Point.from_radians(lat: 0.8990, lon: -0.0022) # London (ish)
# converting to/from radians/degrees
point = point.to_radians
point = point.to_degrees
# distance is in the same units as radius
distance = point.distance_to(point2)
bounds = point.bounds(100) # km
p [bounds[0].lat, bounds[0].lon, bounds[1].lat, bounds[1].lon]
Bug reports and pull requests are welcome on GitHub at https://github.com/sobakasu/jpm_geo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the JpmGeo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.