Skip to content
Location from IP, geocoding, distance calculation, and geo/map utilities
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Geo calculation notes.txt


Geo Magic

This little magic gem attempts to provide a nice DSL for performing Geo functionality.
It levearegs some of my other geo- gems.

Geo Magic should mainly be a DSL sugar-coating on top of these geo gems and integrate them all in a nice, convenient way under the cover.

Main features:

  • Find points within a radius (circle or square from center)
  • Generate random points within a radius (for testing purposes)

Update April 1 2012

Refactoring in progress

Create random points in Radius

From a given radius, you can create random points either in a square or circle radius.

  • create_points_in(shape_type, number)

Example use:

  radius = center_point.within(
  square_points = radius.create_points_in :square, 6
  circle_points = radius.create_points_in :circle 4  

Points within an area or distance

Within distance:


The closest n points:


Or using container objects (objects containing a location):


Where @people is an array of Person and @house is an instance of House and where both House and Person has a #location, #to_point or #point method that returns an object
with latitude and longitude methods that each return a float.

Within bounding rectangle (see Geo::Shapes in ‘geo_shapes’ gem) :

rectangle =, 50),, 20))
# or
# rect = GeoMagic::Rectangle.create_from_coords lat1, long1, lat2, long2

Meta magic

You can also include the functionality directly into any class like this

class Map
  include Geo::Calculate

class MapCalc
  geo_magic :calc

dist = Map.distance [@long1, @lat1], [@long2, @lat2]    

dist = MapCalc.distance [@long1, @lat1], [@long2, @lat2]    

Contributing to geo_magic

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright © 2011 Kristian Mandrup. See LICENSE.txt for
further details.

You can’t perform that action at this time.