gmaps4rails 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +7 -1
- data/README.rdoc +2 -2
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +37 -96
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee +11 -0
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +85 -9
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee +13 -2
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee +54 -2
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +1 -1
- data/gmaps4rails.gemspec +1 -0
- data/lib/generators/gmaps4rails/install_generator.rb +28 -12
- data/lib/gmaps4rails/acts_as_gmappable.rb +3 -46
- data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +40 -0
- data/lib/gmaps4rails/api_wrappers/direction.rb +87 -0
- data/lib/gmaps4rails/api_wrappers/geocoder.rb +54 -0
- data/lib/gmaps4rails/api_wrappers/places.rb +74 -0
- data/lib/gmaps4rails/base.rb +80 -22
- data/lib/gmaps4rails/extensions/{array.rb → enumerable.rb} +1 -1
- data/lib/gmaps4rails/js_builder.rb +9 -17
- data/lib/gmaps4rails/json_builder.rb +1 -7
- data/lib/gmaps4rails/model_handler.rb +79 -0
- data/lib/gmaps4rails/version.rb +1 -1
- data/lib/gmaps4rails/view_helper.rb +4 -6
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +35 -112
- data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +12 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +123 -7
- data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +12 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +53 -2
- data/spec/dummy/app/views/users/index.html.erb +88 -85
- data/spec/fixtures/google_direction_valid.json +65 -0
- data/spec/fixtures/google_geocoding_toulon_france.json +58 -0
- data/spec/fixtures/google_places_valid.json +45 -0
- data/spec/fixtures/google_wrong_geocoding.json +4 -0
- data/spec/lib/base_spec.rb +59 -0
- data/spec/lib/direction_spec.rb +53 -0
- data/spec/lib/geocoder_spec.rb +46 -0
- data/spec/{base/base_spec.rb → lib/js_builder_spec.rb} +0 -6
- data/spec/lib/json_builder_spec.rb +232 -0
- data/spec/lib/places_spec.rb +25 -0
- data/spec/models/user_spec.rb +75 -357
- data/spec/spec_helper.rb +1 -0
- data/spec/support/geocoding.rb +27 -1
- metadata +47 -12
- data/lib/gmaps4rails/geocoding.rb +0 -113
- data/lib/gmaps4rails/google_places.rb +0 -76
- data/spec/base/geocoding_spec.rb +0 -17
@@ -0,0 +1,87 @@
|
|
1
|
+
module Gmaps4rails
|
2
|
+
|
3
|
+
class Direction
|
4
|
+
|
5
|
+
include BaseNetMethods
|
6
|
+
|
7
|
+
attr_reader :ride, :output, :protocol, :options, :polylines, :language
|
8
|
+
attr_accessor :legs
|
9
|
+
|
10
|
+
def initialize(start_end, options= {}, output = "pretty")
|
11
|
+
@ride = OpenStruct.new start_end
|
12
|
+
@output = output
|
13
|
+
@protocol = options.delete(:protocol) || "http"
|
14
|
+
@language = options.delete(:language) || "en"
|
15
|
+
@options = options
|
16
|
+
raise_invalid unless valid?
|
17
|
+
self.legs = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def get
|
21
|
+
checked_google_response do
|
22
|
+
#Each element in the legs array specifies a single leg of the journey from the origin to the destination in the calculated route
|
23
|
+
parsed_response["routes"].first["legs"].each do |leg|
|
24
|
+
extract_polylines(leg) if remove_polylines?
|
25
|
+
self.legs << {
|
26
|
+
"duration" => { "text" => leg["duration"]["text"], "value" => leg["duration"]["value"].to_f },
|
27
|
+
"distance" => { "text" => leg["distance"]["text"], "value" => leg["distance"]["value"].to_f },
|
28
|
+
"steps" => leg["steps"]
|
29
|
+
}
|
30
|
+
merge_polylines_with_leg if output == "pretty"
|
31
|
+
end
|
32
|
+
legs
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def extract_polylines(leg)
|
39
|
+
@polylines = leg["steps"].map {|step| step.delete("polyline")}
|
40
|
+
end
|
41
|
+
|
42
|
+
def polylines_json
|
43
|
+
polylines.map{ |poly| {"coded_array" => poly["points"]} }.to_json
|
44
|
+
end
|
45
|
+
|
46
|
+
def remove_polylines?
|
47
|
+
output == "pretty" || output == "clean"
|
48
|
+
end
|
49
|
+
|
50
|
+
def merge_polylines_with_leg
|
51
|
+
self.legs.last.merge!({ "polylines" => polylines_json })
|
52
|
+
end
|
53
|
+
|
54
|
+
def format_options_for_url
|
55
|
+
return "" if options.empty?
|
56
|
+
"&" + options.map do |k,v|
|
57
|
+
if v.is_a?(Array)
|
58
|
+
k + "=" + v * ("|")
|
59
|
+
else
|
60
|
+
k + "=" + v
|
61
|
+
end
|
62
|
+
end * ("&")
|
63
|
+
end
|
64
|
+
|
65
|
+
def base_request
|
66
|
+
"#{protocol}://maps.googleapis.com/maps/api/directions/json?language=#{language}&origin=#{ride.from}&destination=#{ride.to}&sensor=false" + format_options_for_url
|
67
|
+
end
|
68
|
+
|
69
|
+
def valid?
|
70
|
+
!(ride.from.empty? || ride.to.empty?)
|
71
|
+
end
|
72
|
+
|
73
|
+
def raise_net_status
|
74
|
+
raise Gmaps4rails::DirectionNetStatus, "The request sent to google was invalid (not http success): #{base_request}.\nResponse was: #{response}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def raise_query_error
|
78
|
+
raise raise Gmaps4rails::DirectionStatus, "The query you passed seems invalid, status was: #{parsed_response["status"]}.\nRequest was: #{base_request}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def raise_invalid
|
82
|
+
raise Gmaps4rails::DirectionInvalidQuery, "Origin and destination must be provided in a hash as first argument"
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Gmaps4rails
|
2
|
+
|
3
|
+
class Geocoder
|
4
|
+
include BaseNetMethods
|
5
|
+
|
6
|
+
attr_reader :address, :language, :raw, :protocol
|
7
|
+
|
8
|
+
def initialize(address, options = {})
|
9
|
+
raise Gmaps4rails::GeocodeInvalidQuery, "You must provide an address" if address.empty?
|
10
|
+
|
11
|
+
@address = address
|
12
|
+
@language = options[:language] || "en"
|
13
|
+
@raw = options[:raw] || false
|
14
|
+
@protocol = options[:protocol] || "http"
|
15
|
+
end
|
16
|
+
|
17
|
+
# returns an array of hashes with the following keys:
|
18
|
+
# - lat: mandatory for acts_as_gmappable
|
19
|
+
# - lng: mandatory for acts_as_gmappable
|
20
|
+
# - matched_address: facultative
|
21
|
+
# - bounds: facultative
|
22
|
+
# - full_data: facultative
|
23
|
+
def get_coordinates
|
24
|
+
checked_google_response do
|
25
|
+
return parsed_response if raw
|
26
|
+
parsed_response["results"].inject([]) do |memo, result|
|
27
|
+
memo << {
|
28
|
+
:lat => result["geometry"]["location"]["lat"],
|
29
|
+
:lng => result["geometry"]["location"]["lng"],
|
30
|
+
:matched_address => result["formatted_address"],
|
31
|
+
:bounds => result["geometry"]["bounds"],
|
32
|
+
:full_data => result
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def base_request
|
41
|
+
"#{protocol}://maps.googleapis.com/maps/api/geocode/json?language=#{language}&address=#{address}&sensor=false"
|
42
|
+
end
|
43
|
+
|
44
|
+
def raise_net_status
|
45
|
+
raise Gmaps4rails::GeocodeNetStatus, "The request sent to google was invalid (not http success): #{base_request}.\nResponse was: #{response}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def raise_query_error
|
49
|
+
raise Gmaps4rails::GeocodeStatus, "The address you passed seems invalid, status was: #{parsed_response["status"]}.\nRequest was: #{base_request}"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Gmaps4rails
|
2
|
+
|
3
|
+
class Places
|
4
|
+
|
5
|
+
include BaseNetMethods
|
6
|
+
|
7
|
+
attr_reader :lat, :lng
|
8
|
+
delegate :key, :keyword, :radius, :lang, :raw, :protocol, :to => :@options
|
9
|
+
|
10
|
+
def initialize(lat, lng, options = {})
|
11
|
+
@lat, @lng = lat, lng
|
12
|
+
raise_invalid unless valid_position?
|
13
|
+
raise_missing_key unless options[:key]
|
14
|
+
options[:radius] ||= 7500
|
15
|
+
options[:lang] ||= "en"
|
16
|
+
options[:raw] ||= false
|
17
|
+
options[:protocol]||= "http"
|
18
|
+
@options = OpenStruct.new options
|
19
|
+
end
|
20
|
+
|
21
|
+
def get
|
22
|
+
checked_google_response do
|
23
|
+
return parsed_response if raw
|
24
|
+
parsed_response["results"].inject([]) do |memo, result|
|
25
|
+
memo << {
|
26
|
+
:lat => result["geometry"]["location"]["lat"],
|
27
|
+
:lng => result["geometry"]["location"]["lng"],
|
28
|
+
:name => result["name"],
|
29
|
+
:reference => result["reference"],
|
30
|
+
:vicinity => result["vicinity"],
|
31
|
+
:full_data => result
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def base_request
|
40
|
+
req = "#{protocol}://maps.googleapis.com/maps/api/place/search/json?language=#{lang}&location=#{lat},#{lng}&sensor=false&radius=#{radius}&key=#{key}"
|
41
|
+
req += "&keyword=#{keyword}" unless keyword.nil?
|
42
|
+
req
|
43
|
+
end
|
44
|
+
|
45
|
+
def valid_position?
|
46
|
+
!(lat.nil? || lng.nil?)
|
47
|
+
end
|
48
|
+
|
49
|
+
def raise_invalid
|
50
|
+
raise Gmaps4rails::PlacesInvalidQuery, "You must provide at least a lat/lon for a Google places query"
|
51
|
+
end
|
52
|
+
|
53
|
+
def raise_missing_key
|
54
|
+
raise "Google Places API requires an API key"
|
55
|
+
end
|
56
|
+
|
57
|
+
def raise_net_status
|
58
|
+
raise Gmaps4rails::PlacesNetStatus, "The request sent to google was invalid (not http success): #{base_request}.\nResponse was: #{response}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def raise_query_error
|
62
|
+
raise Gmaps4rails::PlacesStatus, "The address you passed seems invalid, status was: #{parsed_response["status"]}.\nRequest was: #{base_request}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_response
|
66
|
+
uri = URI.parse(base_url)
|
67
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
68
|
+
http.use_ssl = true # Places API wants https
|
69
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # to avoid any cert issues
|
70
|
+
http.request(Net::HTTP::Get.new(uri.request_uri))
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/lib/gmaps4rails/base.rb
CHANGED
@@ -1,17 +1,86 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require 'gmaps4rails/view_helper'
|
6
|
-
require 'gmaps4rails/geocoding'
|
7
|
-
require 'gmaps4rails/google_places'
|
8
|
-
require 'gmaps4rails/extensions/array'
|
9
|
-
require 'gmaps4rails/extensions/hash'
|
10
|
-
|
11
|
-
require 'gmaps4rails/helper/gmaps4rails_helper'
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
require 'ostruct'
|
12
5
|
|
13
6
|
module Gmaps4rails
|
7
|
+
|
8
|
+
require 'gmaps4rails/extensions/enumerable'
|
9
|
+
require 'gmaps4rails/extensions/hash'
|
10
|
+
|
11
|
+
autoload :ModelHandler, 'gmaps4rails/model_handler'
|
12
|
+
autoload :ActsAsGmappable, 'gmaps4rails/acts_as_gmappable'
|
14
13
|
|
14
|
+
autoload :JsBuilder, 'gmaps4rails/js_builder'
|
15
|
+
autoload :JsonBuilder, 'gmaps4rails/json_builder'
|
16
|
+
autoload :ViewHelper, 'gmaps4rails/view_helper'
|
17
|
+
autoload :Gmaps4railsHelper,'gmaps4rails/helper/gmaps4rails_helper'
|
18
|
+
|
19
|
+
autoload :BaseNetMethods, 'gmaps4rails/api_wrappers/base_net_methods'
|
20
|
+
autoload :Geocoder, 'gmaps4rails/api_wrappers/geocoder'
|
21
|
+
autoload :Direction, 'gmaps4rails/api_wrappers/direction'
|
22
|
+
autoload :Places, 'gmaps4rails/api_wrappers/places'
|
23
|
+
|
24
|
+
mattr_accessor :http_proxy
|
25
|
+
|
26
|
+
# This method geocodes an address using the GoogleMaps webservice
|
27
|
+
# options are:
|
28
|
+
# * address: string, mandatory
|
29
|
+
# * lang: to set the language one wants the result to be translated (default is english)
|
30
|
+
# * raw: to get the raw response from google, default is false
|
31
|
+
def Gmaps4rails.geocode(address, lang="en", raw = false, protocol = "http")
|
32
|
+
::Gmaps4rails::Geocoder.new(address, {
|
33
|
+
:language => lang,
|
34
|
+
:raw => raw,
|
35
|
+
:protocol => protocol
|
36
|
+
}).get_coordinates
|
37
|
+
end
|
38
|
+
|
39
|
+
def Gmaps4rails.create_json(object, &block)
|
40
|
+
::Gmaps4rails::JsonBuilder.new(object).process(&block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def Gmaps4rails.create_js_from_hash(hash)
|
44
|
+
::Gmaps4rails::JsBuilder.new(hash).create_js
|
45
|
+
end
|
46
|
+
|
47
|
+
# This method retrieves destination results provided by GoogleMaps webservice
|
48
|
+
# options are:
|
49
|
+
# * start_end: Hash { "from" => string, "to" => string}, mandatory
|
50
|
+
# * options: details given in the github's wiki
|
51
|
+
# * output: could be "pretty", "raw" or "clean"; filters the output from google
|
52
|
+
#output could be raw, pretty or clean
|
53
|
+
def Gmaps4rails.destination(start_end, options={}, output="pretty")
|
54
|
+
Gmaps4rails::Direction.new(start_end, options, output).get
|
55
|
+
end
|
56
|
+
|
57
|
+
# does two things... 1) gecode the given address string and 2) triggers a a places query around that geo location
|
58
|
+
# optionally a keyword can be given for a filter over all places fields (e.g. "Bungy" to give all Bungy related places)
|
59
|
+
# IMPORTANT: Places API calls require an API key (param "key")
|
60
|
+
|
61
|
+
def Gmaps4rails.places_for_address(address, key, keyword = nil, radius = 7500, lang="en", raw = false)
|
62
|
+
raise Gmaps4rails::GeocodeInvalidQuery, "you must provide an address for a places_for_address query" if address.nil?
|
63
|
+
raise "Google Places API requires an API key" if key.nil?
|
64
|
+
res = Gmaps4rails.geocode(address) # will throw exception if nothing could be geocoded
|
65
|
+
Gmaps4rails.places(res.first[:lat], res.first[:lng], key, keyword, radius, lang, raw)
|
66
|
+
end
|
67
|
+
|
68
|
+
# does a places query around give geo location (lat/lng)
|
69
|
+
# optionally a keyword can be given for a filter over all places fields (e.g. "Bungy" to give all Bungy related places)
|
70
|
+
# IMPORTANT: Places API calls require an API key (param "key")
|
71
|
+
def Gmaps4rails.places(lat, lng, key, keyword = nil, radius = 7500, lang="en", raw = false, protocol = "https")
|
72
|
+
Gmaps4rails::Places.new(lat, lng, {
|
73
|
+
:key => key,
|
74
|
+
:keyword => keyword,
|
75
|
+
:radius => radius,
|
76
|
+
:lang => lang,
|
77
|
+
:raw => raw,
|
78
|
+
:protocol => protocol
|
79
|
+
}).get
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
15
84
|
class GeocodeStatus < StandardError; end
|
16
85
|
class GeocodeNetStatus < StandardError; end
|
17
86
|
class GeocodeInvalidQuery < StandardError; end
|
@@ -23,8 +92,6 @@ module Gmaps4rails
|
|
23
92
|
class PlacesStatus < StandardError; end
|
24
93
|
class PlacesNetStatus < StandardError; end
|
25
94
|
class PlacesInvalidQuery < StandardError; end
|
26
|
-
|
27
|
-
mattr_accessor :http_proxy
|
28
95
|
|
29
96
|
def Gmaps4rails.condition_eval(object, condition)
|
30
97
|
case condition
|
@@ -34,15 +101,6 @@ module Gmaps4rails
|
|
34
101
|
end
|
35
102
|
end
|
36
103
|
|
37
|
-
private
|
38
|
-
|
39
|
-
# get the response from the url encoded address string
|
40
|
-
def Gmaps4rails.get_response(url)
|
41
|
-
url = URI.parse(url)
|
42
|
-
http = Gmaps4rails.http_agent
|
43
|
-
http.get_response(url)
|
44
|
-
end
|
45
|
-
|
46
104
|
# looks for proxy settings and returns a Net::HTTP or Net::HTTP::Proxy class
|
47
105
|
def Gmaps4rails.http_agent
|
48
106
|
proxy = ENV['HTTP_PROXY'] || ENV['http_proxy'] || self.http_proxy
|
@@ -1,9 +1,4 @@
|
|
1
1
|
module Gmaps4rails
|
2
|
-
|
3
|
-
def Gmaps4rails.create_js_from_hash(hash)
|
4
|
-
::Gmaps4rails::JsBuilder.new(hash).create_js
|
5
|
-
end
|
6
|
-
|
7
2
|
class JsBuilder
|
8
3
|
|
9
4
|
DEFAULT_MAP_ID = "map"
|
@@ -94,9 +89,13 @@ module Gmaps4rails
|
|
94
89
|
class Datum
|
95
90
|
# example:
|
96
91
|
# - name: :markers
|
97
|
-
# - hash: { :data => json, :options => hash }
|
92
|
+
# - hash: { :data => json, :options => hash }
|
93
|
+
|
94
|
+
delegate :options, :data, :to => :@element_info
|
95
|
+
|
98
96
|
def initialize(gmap_id, name, hash)
|
99
|
-
@gmap_id, @
|
97
|
+
@gmap_id, @name, @js = gmap_id, name, Array.new
|
98
|
+
@element_info = OpenStruct.new(hash)
|
100
99
|
end
|
101
100
|
|
102
101
|
def create_js
|
@@ -108,7 +107,7 @@ module Gmaps4rails
|
|
108
107
|
end
|
109
108
|
|
110
109
|
def create_standard_js
|
111
|
-
@js << "#{@gmap_id}.#{@name} = #{
|
110
|
+
@js << "#{@gmap_id}.#{@name} = #{data};"
|
112
111
|
|
113
112
|
set_configuration_variables
|
114
113
|
|
@@ -116,8 +115,8 @@ module Gmaps4rails
|
|
116
115
|
end
|
117
116
|
|
118
117
|
def create_direction_js
|
119
|
-
@js << "#{@gmap_id}.direction_conf.origin = '#{
|
120
|
-
@js << "#{@gmap_id}.direction_conf.destination = '#{
|
118
|
+
@js << "#{@gmap_id}.direction_conf.origin = '#{data["from"]}';"
|
119
|
+
@js << "#{@gmap_id}.direction_conf.destination = '#{data["to"]}';"
|
121
120
|
|
122
121
|
set_direction_variables
|
123
122
|
|
@@ -150,13 +149,6 @@ module Gmaps4rails
|
|
150
149
|
end
|
151
150
|
end
|
152
151
|
|
153
|
-
def options
|
154
|
-
@hash[:options]
|
155
|
-
end
|
156
|
-
|
157
|
-
def value
|
158
|
-
@hash[:data]
|
159
|
-
end
|
160
152
|
end
|
161
153
|
end
|
162
154
|
|
@@ -1,10 +1,4 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
|
3
|
-
def Gmaps4rails.create_json(object, &block)
|
4
|
-
json_handler = ::Gmaps4rails::JsonBuilder.new(object, &block)
|
5
|
-
json_handler.process(&block)
|
6
|
-
end
|
7
|
-
|
1
|
+
module Gmaps4rails
|
8
2
|
# the to_gmaps4rails method accepts a block to customize:
|
9
3
|
# - infowindow
|
10
4
|
# - picture
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Gmaps4rails
|
2
|
+
|
3
|
+
class ModelHandler
|
4
|
+
|
5
|
+
attr_accessor :options, :object
|
6
|
+
|
7
|
+
delegate :process_geocoding, :check_process, :checker, :lat_column, :lng_column, :msg, :validation,
|
8
|
+
:language, :protocol, :address, :callback, :normalized_address,
|
9
|
+
:to => :@options
|
10
|
+
|
11
|
+
def initialize(object, gmaps4rails_options)
|
12
|
+
@options = ::OpenStruct.new(gmaps4rails_options)
|
13
|
+
@object = object
|
14
|
+
end
|
15
|
+
|
16
|
+
# saves coordinates according to the various options
|
17
|
+
def retrieve_coordinates
|
18
|
+
return if prevent_geocoding?
|
19
|
+
checked_coordinates do
|
20
|
+
object.send("#{lng_column}=", coordinates.first[:lng])
|
21
|
+
object.send("#{lat_column}=", coordinates.first[:lat])
|
22
|
+
# save normalized address if required
|
23
|
+
object.send("#{normalized_address}=", coordinates.first[:matched_address]) if normalized_address
|
24
|
+
# Call the callback method to let the user do what he wants with the data
|
25
|
+
object.send(callback, coordinates.first[:full_data]) if callback
|
26
|
+
# update checker if required
|
27
|
+
object.send("#{checker}=", true) if check_geocoding?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def checked_coordinates(&block)
|
34
|
+
yield if coordinates
|
35
|
+
end
|
36
|
+
|
37
|
+
def coordinates
|
38
|
+
@coordinates ||= get_coordinates
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_coordinates
|
42
|
+
Gmaps4rails.geocode(object.send(address), language, false, protocol)
|
43
|
+
rescue GeocodeStatus, GeocodeInvalidQuery => e #address was invalid, add error to address.
|
44
|
+
Rails.logger.warn(e)
|
45
|
+
object.errors[address] << msg if condition_eval(object, validation)
|
46
|
+
false
|
47
|
+
rescue GeocodeNetStatus => e #connection error, No need to prevent save.
|
48
|
+
Rails.logger.warn(e)
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
# to prevent geocoding each time a save is made
|
53
|
+
# if process_geocoding is a TrueClass or a FalseClass, 'check_process' and 'checker' play an additional role
|
54
|
+
# if process_geocoding is a Proc or a Symbol, 'check_process' and 'checker' are skipped since process_geocoding bears the whole logic
|
55
|
+
def prevent_geocoding?
|
56
|
+
if process_geocoding.is_a?(TrueClass) || process_geocoding.is_a?(FalseClass)
|
57
|
+
return true if !condition_eval(object, process_geocoding)
|
58
|
+
condition_eval(object, check_process) && object.send(checker)
|
59
|
+
else
|
60
|
+
!condition_eval(object, process_geocoding)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Do we have to check the geocoding
|
65
|
+
def check_geocoding?
|
66
|
+
if process_geocoding.is_a?(TrueClass) || process_geocoding.is_a?(FalseClass)
|
67
|
+
condition_eval(object, check_process)
|
68
|
+
else
|
69
|
+
false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def condition_eval(*args)
|
74
|
+
Gmaps4rails.condition_eval(*args)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/lib/gmaps4rails/version.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
|
3
1
|
module Gmaps4rails
|
4
2
|
|
5
3
|
class ViewHelper
|
6
4
|
|
7
5
|
OPENLAYERS = "http://www.openlayers.org/api/OpenLayers.js"
|
8
|
-
MAPQUEST = "http://mapquestapi.com/sdk/js/
|
6
|
+
MAPQUEST = "http://www.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js"
|
9
7
|
BING = "http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"
|
10
8
|
GOOGLE = "//maps.google.com/maps/api/js?v=3.8"
|
11
9
|
GOOGLE_EXT = "//google-maps-utility-library-v3.googlecode.com/svn/"
|
@@ -69,9 +67,9 @@ module Gmaps4rails
|
|
69
67
|
when "bing" then @js_array << BING
|
70
68
|
else #case googlemaps which is the default
|
71
69
|
@js_array << "#{GOOGLE}&sensor=false&key=#{provider_key}&libraries=geometry#{google_libraries}&#{google_map_i18n}"
|
72
|
-
@js_array << "#{GOOGLE_EXT}tags/infobox/1.1.9/src/infobox_packed.js"
|
73
|
-
@js_array << "#{GOOGLE_EXT}tags/markerclustererplus/2.0.
|
74
|
-
@js_array << "#{GOOGLE_EXT}trunk/richmarker/src/richmarker-compiled.js"
|
70
|
+
@js_array << "#{GOOGLE_EXT}tags/infobox/1.1.9/src/infobox_packed.js" if custom_infowindow_class
|
71
|
+
@js_array << "#{GOOGLE_EXT}tags/markerclustererplus/2.0.9/src/markerclusterer_packed.js" if do_clustering
|
72
|
+
@js_array << "#{GOOGLE_EXT}trunk/richmarker/src/richmarker-compiled.js" if rich_marker
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|