Module: Gmaps4rails

Defined in:
lib/gmaps4rails.rb,
lib/gmaps4rails/base.rb,
lib/gmaps4rails/version.rb,
lib/gmaps4rails/js_builder.rb,
lib/gmaps4rails/view_helper.rb,
lib/gmaps4rails/json_builder.rb,
lib/gmaps4rails/model_handler.rb,
lib/gmaps4rails/acts_as_gmappable.rb,
lib/gmaps4rails/api_wrappers/places.rb,
lib/gmaps4rails/api_wrappers/geocoder.rb,
lib/gmaps4rails/api_wrappers/direction.rb,
lib/generators/gmaps4rails/install_generator.rb,
lib/gmaps4rails/api_wrappers/base_net_methods.rb

Defined Under Namespace

Modules: ActsAsGmappable, BaseNetMethods, Generators Classes: Direction, DirectionInvalidQuery, DirectionNetStatus, DirectionStatus, Engine, GeocodeInvalidQuery, GeocodeNetStatus, GeocodeStatus, Geocoder, JsBuilder, JsonBuilder, ModelHandler, Places, PlacesInvalidQuery, PlacesNetStatus, PlacesStatus, Railtie, ViewHelper

Constant Summary collapse

VERSION =
"1.5.6"

Class Method Summary collapse

Class Method Details

.create_js_from_hash(hash) ⇒ Object



46
47
48
# File 'lib/gmaps4rails/base.rb', line 46

def Gmaps4rails.create_js_from_hash(hash)
  ::Gmaps4rails::JsBuilder.new(hash).create_js
end

.create_json(object, &block) ⇒ Object



42
43
44
# File 'lib/gmaps4rails/base.rb', line 42

def Gmaps4rails.create_json(object, &block)
  ::Gmaps4rails::JsonBuilder.new(object).process(&block)
end

.destination(start_end, options = {}, output = "pretty") ⇒ Object

This method retrieves destination results provided by GoogleMaps webservice options are:

  • start_end: Hash { “from” => string, “to” => string}, mandatory

  • options: details given in the github’s wiki

  • output: could be “pretty”, “raw” or “clean”; filters the output from google

output could be raw, pretty or clean



56
57
58
# File 'lib/gmaps4rails/base.rb', line 56

def Gmaps4rails.destination(start_end, options={}, output="pretty")
   Gmaps4rails::Direction.new(start_end, options, output).get
end

.geocode(address, lang = "en", raw = false, protocol = "http") ⇒ Object

This method geocodes an address using the GoogleMaps webservice options are:

  • address: string, mandatory

  • lang: to set the language one wants the result to be translated (default is english)

  • raw: to get the raw response from google, default is false



34
35
36
37
38
39
40
# File 'lib/gmaps4rails/base.rb', line 34

def Gmaps4rails.geocode(address, lang="en", raw = false, protocol = "http")
  ::Gmaps4rails::Geocoder.new(address, {
    :language => lang, 
    :raw      => raw,
    :protocol => protocol
  }).get_coordinates
end

.places(lat, lng, key, keyword = nil, radius = 7500, lang = "en", raw = false, protocol = "https") ⇒ Object

does a places query around give geo location (lat/lng) optionally a keyword can be given for a filter over all places fields (e.g. “Bungy” to give all Bungy related places) IMPORTANT: Places API calls require an API key (param “key”)



74
75
76
77
78
79
80
81
82
83
# File 'lib/gmaps4rails/base.rb', line 74

def Gmaps4rails.places(lat, lng, key, keyword = nil, radius = 7500, lang="en", raw = false, protocol = "https")
  Gmaps4rails::Places.new(lat, lng, {
    :key      => key,
    :keyword  => keyword,
    :radius   => radius, 
    :lang     => lang,
    :raw      => raw,
    :protocol => protocol
  }).get
end

.places_for_address(address, key, keyword = nil, radius = 7500, lang = "en", raw = false) ⇒ Object

does two things… 1) gecode the given address string and 2) triggers a a places query around that geo location optionally a keyword can be given for a filter over all places fields (e.g. “Bungy” to give all Bungy related places) IMPORTANT: Places API calls require an API key (param “key”)



64
65
66
67
68
69
# File 'lib/gmaps4rails/base.rb', line 64

def Gmaps4rails.places_for_address(address, key, keyword = nil, radius = 7500, lang="en", raw = false)
  raise Gmaps4rails::GeocodeInvalidQuery, "you must provide an address for a places_for_address query" if address.nil?
  raise "Google Places API requires an API key" if key.nil?
  res = Gmaps4rails.geocode(address)  # will throw exception if nothing could be geocoded
  Gmaps4rails.places(res.first[:lat], res.first[:lng], key, keyword, radius, lang, raw)
end