Location from IP, geocoding, distance calculation, and geo/map utilities

Latest commit to the master branch

README.textile

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(10.km)
  square_points = radius.create_points_in :square, 6
  circle_points = radius.create_points_in :circle 4  

Points within an area or distance

Within distance:

@points.as_map_points.within(4.km).of(@center_point)

The closest n points:

@points.as_map_points.the_closest(4).from(@center_point)

Or using container objects (objects containing a location):

@people.as_map_points.the_closest(4).from(@house)

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 = GeoMagic::Rectangle.new(GeoMagic::Point.new(-115, 50), GeoMagic::Point.new(-100, 20))
# or
# rect = GeoMagic::Rectangle.create_from_coords lat1, long1, lat2, long2
@points.as_map_points.within_rectangle(rect).from(@center_point)

Meta magic

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

class Map
  include Geo::Calculate
end

class MapCalc
  geo_magic :calc
end

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

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



Markdown Cheat Sheet

Format Text

Headers

# This is an <h1> tag
## This is an <h2> tag
###### This is an <h6> tag

Text styles

*This text will be italic*
_This will also be italic_
**This text will be bold**
__This will also be bold__

*You **can** combine them*

Lists

Unordered

* Item 1
* Item 2
  * Item 2a
  * Item 2b

Ordered

1. Item 1
2. Item 2
3. Item 3
   * Item 3a
   * Item 3b

Miscellaneous

Images

![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)

Links

http://github.com - automatic!
[GitHub](http://github.com)

Blockquotes

As Kanye West said:

> We're living the future so
> the present is our past.

Code Examples in Markdown

Syntax highlighting with GFM

```javascript
function fancyAlert(arg) {
  if(arg) {
    $.facebox({div:'#foo'})
  }
}
```

Or, indent your code 4 spaces

Here is a Python code example
without syntax highlighting:

    def foo:
      if not bar:
        return true

Inline code for comments

I think you should use an
`<addr>` element here instead.
Something went wrong with that request. Please try again. Dismiss

Looking for the GitHub logo?