Skip to content
Location from IP, geocoding, distance calculation, and geo/map utilities
Failed to load latest commit information.
spec extracted all remote functionality into geo-remote gem Apr 1, 2012
.document Initial commit to geo_magic. Jan 12, 2011
.rspec added better dist calc specs Jan 13, 2011
Gemfile initial version after refactoring Apr 1, 2012
Gemfile.lock initial version after refactoring Apr 1, 2012
Geo calculation notes.txt distance calc notes May 11, 2011
LICENSE.txt Initial commit to geo_magic. Jan 12, 2011
README.textile extracted all remote functionality into geo-remote gem Apr 1, 2012
Rakefile core ext specs ok Feb 6, 2011
VERSION extracted all remote functionality into geo-remote gem Apr 1, 2012
geo_magic.gemspec Regenerate gemspec for version Feb 1, 2011
rspec_examples.rb lots of improvements Feb 24, 2011


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.

Something went wrong with that request. Please try again.