Module: GoogleStaticMapsHelper

Defined in:
lib/google_static_maps_helper.rb,
lib/google_static_maps_helper/map.rb,
lib/google_static_maps_helper/path.rb,
lib/google_static_maps_helper/marker.rb,
lib/google_static_maps_helper/location.rb

Overview

The Google Static Map Helper provides a simple interface to the Google Static Maps V2 API (code.google.com/apis/maps/documentation/staticmaps/).

The module is build up of classes maping more or less directly to the entities you’d except:

Map

A map is what keeps all of the state of which you’ll build a URL for.

Marker

One or more markers can be added to the map. A marker can be customized with size, label and color.

Path

A path will create lines or polygons in your map.

About

Author

Thorbjørn Hermansen ([email protected])

Defined Under Namespace

Classes: BuildDataMissing, Location, Map, Marker, OptionMissing, OptionNotExist, Path, UnsupportedFormat, UnsupportedMaptype

Constant Summary collapse

API_URL =

The basic url to the API which we’ll build the URL from

'http://maps.google.com/maps/api/staticmap'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.keyObject

Returns the value of attribute key.



31
32
33
# File 'lib/google_static_maps_helper.rb', line 31

def key
  @key
end

.sensorObject

Returns the value of attribute sensor.



31
32
33
# File 'lib/google_static_maps_helper.rb', line 31

def sensor
  @sensor
end

.sizeObject

Returns the value of attribute size.



31
32
33
# File 'lib/google_static_maps_helper.rb', line 31

def size
  @size
end

Class Method Details

.url_for(map_options = {}, &block) ⇒ Object

Provides a simple DSL stripping away the need of manually instantiating classes

NOTE Paths are not supported by the DSL yet.

Usage:

# First of all, you might want to set your key etc
GoogleStaticMapsHelper.key = 'your google key'
GoogleStaticMapsHelper.size = '300x600'
GoogleStaticMapsHelper.sensor = false

# Then, you'll be able to do:
url = GoogleStaticMapsHelper.url_for do
  marker :lng => 1, :lat => 2
  marker :lng => 3, :lat => 4
end

# You can send in key, size etc to url_for
url = GoogleStaticMapsHelper.url_for(:key => 'your_key', :size => [300, 600]) do
  # ...
end

# If you need to, the map object is yielded to the block, so you can do:
url = GoogleStaticMapsHelper.url_for do |map|
  map.marker object_which_responds_to_lng_lat
end


61
62
63
64
65
# File 'lib/google_static_maps_helper.rb', line 61

def url_for(map_options = {}, &block)
  map = Map.new(map_options)
  block.arity < 1 ? map.instance_eval(&block) : block.call(map)
  map.url
end