google_maps_service 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +11 -0
- data/CHANGELOG.md +34 -0
- data/README.md +299 -56
- data/google_maps_service.gemspec +3 -2
- data/lib/google_maps_service.rb +42 -9
- data/lib/google_maps_service/apis.rb +6 -0
- data/lib/google_maps_service/{directions.rb → apis/directions.rb} +38 -25
- data/lib/google_maps_service/{distance_matrix.rb → apis/distance_matrix.rb} +40 -21
- data/lib/google_maps_service/{elevation.rb → apis/elevation.rb} +22 -21
- data/lib/google_maps_service/apis/geocoding.rb +85 -0
- data/lib/google_maps_service/{roads.rb → apis/roads.rb} +68 -38
- data/lib/google_maps_service/{time_zone.rb → apis/time_zone.rb} +12 -7
- data/lib/google_maps_service/client.rb +175 -158
- data/lib/google_maps_service/convert.rb +19 -79
- data/lib/google_maps_service/errors.rb +13 -4
- data/lib/google_maps_service/polyline.rb +90 -0
- data/lib/google_maps_service/url.rb +64 -0
- data/lib/google_maps_service/validator.rb +16 -0
- data/lib/google_maps_service/version.rb +21 -1
- metadata +28 -25
- data/bin/console +0 -14
- data/bin/setup +0 -7
- data/lib/google_maps_service/geocoding.rb +0 -58
data/google_maps_service.gemspec
CHANGED
@@ -9,9 +9,10 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Edward Samuel Pasaribu']
|
10
10
|
spec.email = ['edwardsamuel92@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = %q{Ruby
|
12
|
+
spec.summary = %q{Ruby gem for Google Maps Web Service APIs }
|
13
13
|
spec.homepage = %q{https://github.com/edwardsamuel/google-maps-services-ruby}
|
14
14
|
spec.license = 'Apache-2.0'
|
15
|
+
spec.required_ruby_version = '>= 2.0.0'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
18
|
spec.require_paths = ['lib']
|
@@ -20,10 +21,10 @@ Gem::Specification.new do |spec|
|
|
20
21
|
spec.add_runtime_dependency 'multi_json', '~> 1.11'
|
21
22
|
spec.add_runtime_dependency 'hurley', '~> 0.1'
|
22
23
|
spec.add_runtime_dependency 'retriable', '~> 2.0', '>= 2.0.2'
|
23
|
-
spec.add_runtime_dependency 'ruby-hmac', '~> 0.4.0'
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
26
|
spec.add_development_dependency 'yard', '~> 0.8.7.6'
|
27
|
+
spec.add_development_dependency 'redcarpet', '~> 3.3'
|
27
28
|
spec.add_development_dependency 'rspec', '~> 3.3'
|
28
29
|
spec.add_development_dependency 'simplecov', '~> 0.10.0'
|
29
30
|
spec.add_development_dependency 'coveralls', '~> 0.8.2'
|
data/lib/google_maps_service.rb
CHANGED
@@ -1,6 +1,46 @@
|
|
1
|
+
# Google Maps Web Service API.
|
1
2
|
module GoogleMapsService
|
2
3
|
class << self
|
3
|
-
|
4
|
+
|
5
|
+
# Global key.
|
6
|
+
# @see Client#key
|
7
|
+
# @return [String]
|
8
|
+
attr_accessor :key
|
9
|
+
|
10
|
+
# Global client_id.
|
11
|
+
# @see Client#client_id
|
12
|
+
# @return [String]
|
13
|
+
attr_accessor :client_id
|
14
|
+
|
15
|
+
# Global client_secret.
|
16
|
+
# @see Client#client_secret
|
17
|
+
# @return [String]
|
18
|
+
attr_accessor :client_secret
|
19
|
+
|
20
|
+
# Global retry_timeout.
|
21
|
+
# @see Client#retry_timeout
|
22
|
+
# @return [Integer]
|
23
|
+
attr_accessor :retry_timeout
|
24
|
+
|
25
|
+
# Global queries_per_second.
|
26
|
+
# @see Client#queries_per_second
|
27
|
+
# @return [Integer]
|
28
|
+
attr_accessor :queries_per_second
|
29
|
+
|
30
|
+
# Global request_options.
|
31
|
+
# @see Client#initialize-instance_method
|
32
|
+
# @return [Hurley::RequestOptions]
|
33
|
+
attr_accessor :request_options
|
34
|
+
|
35
|
+
# Global ssl_options.
|
36
|
+
# @see Client#initialize-instance_method
|
37
|
+
# @return [Hurley::SslOptions]
|
38
|
+
attr_accessor :ssl_options
|
39
|
+
|
40
|
+
# Global connection.
|
41
|
+
# @see Client#initialize-instance_method
|
42
|
+
# @return [Object]
|
43
|
+
attr_accessor :connection
|
4
44
|
|
5
45
|
def configure
|
6
46
|
yield self
|
@@ -9,13 +49,6 @@ module GoogleMapsService
|
|
9
49
|
end
|
10
50
|
|
11
51
|
require 'google_maps_service/version'
|
12
|
-
require 'google_maps_service/errors'
|
13
|
-
require 'google_maps_service/convert'
|
14
|
-
require 'google_maps_service/directions'
|
15
|
-
require 'google_maps_service/distance_matrix'
|
16
|
-
require 'google_maps_service/elevation'
|
17
|
-
require 'google_maps_service/geocoding'
|
18
|
-
require 'google_maps_service/roads'
|
19
|
-
require 'google_maps_service/time_zone'
|
20
52
|
require 'google_maps_service/client'
|
53
|
+
require 'google_maps_service/polyline'
|
21
54
|
end
|
@@ -1,18 +1,39 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../validator'
|
2
2
|
|
3
|
-
module GoogleMapsService
|
3
|
+
module GoogleMapsService::Apis
|
4
4
|
|
5
5
|
# Performs requests to the Google Maps Directions API.
|
6
6
|
module Directions
|
7
7
|
|
8
8
|
# Get directions between an origin point and a destination point.
|
9
9
|
#
|
10
|
+
# @example Simple directions
|
11
|
+
# routes = client.directions('Sydney', 'Melbourne')
|
12
|
+
#
|
13
|
+
# @example Complex bicycling directions
|
14
|
+
# routes = client.directions('Sydney', 'Melbourne',
|
15
|
+
# mode: 'bicycling',
|
16
|
+
# avoid: ['highways', 'tolls', 'ferries'],
|
17
|
+
# units: 'metric',
|
18
|
+
# region: 'au')
|
19
|
+
#
|
20
|
+
# @example Public transportation directions
|
21
|
+
# an_hour_from_now = Time.now - (1.0/24)
|
22
|
+
# routes = client.directions('Sydney Town Hall', 'Parramatta, NSW',
|
23
|
+
# mode: 'transit',
|
24
|
+
# arrival_time: an_hour_from_now)
|
25
|
+
#
|
26
|
+
# @example Walking with alternative routes
|
27
|
+
# routes = client.directions('Sydney Town Hall', 'Parramatta, NSW',
|
28
|
+
# mode: 'walking',
|
29
|
+
# alternatives: true)
|
30
|
+
#
|
10
31
|
# @param [String, Hash, Array] origin The address or latitude/longitude value from which you wish
|
11
32
|
# to calculate directions.
|
12
33
|
# @param [String, Hash, Array] destination The address or latitude/longitude value from which
|
13
34
|
# you wish to calculate directions.
|
14
35
|
# @param [String] mode Specifies the mode of transport to use when calculating
|
15
|
-
# directions. One of
|
36
|
+
# directions. One of `driving`, `walking`, `bicycling` or `transit`.
|
16
37
|
# @param [Array<String>, Array<Hash>, Array<Array>] waypoints Specifies an array of waypoints. Waypoints alter a
|
17
38
|
# route by routing it through the specified location(s).
|
18
39
|
# @param [Boolean] alternatives If True, more than one route may be returned in the
|
@@ -21,40 +42,40 @@ module GoogleMapsService
|
|
21
42
|
# indicated features.
|
22
43
|
# @param [String] language The language in which to return results.
|
23
44
|
# @param [String] units Specifies the unit system to use when displaying results.
|
24
|
-
#
|
25
|
-
# @param [String] region The region code, specified as a ccTLD (
|
45
|
+
# `metric` or `imperial`.
|
46
|
+
# @param [String] region The region code, specified as a ccTLD (_top-level domain_)
|
26
47
|
# two-character value.
|
27
48
|
# @param [Integer, DateTime] departure_time Specifies the desired time of departure.
|
28
49
|
# @param [Integer, DateTime] arrival_time Specifies the desired time of arrival for transit
|
29
|
-
# directions. Note: you can
|
30
|
-
# arrival_time
|
50
|
+
# directions. Note: you can not specify both `departure_time` and
|
51
|
+
# `arrival_time`.
|
31
52
|
# @param [Boolean] optimize_waypoints Optimize the provided route by rearranging the
|
32
53
|
# waypoints in a more efficient order.
|
33
54
|
# @param [String, Array<String>] transit_mode Specifies one or more preferred modes of transit.
|
34
55
|
# This parameter may only be specified for requests where the mode is
|
35
|
-
# transit. Valid values are
|
36
|
-
#
|
56
|
+
# transit. Valid values are `bus`, `subway`, `train`, `tram` or `rail`.
|
57
|
+
# `rail` is equivalent to `["train", "tram", "subway"]`.
|
37
58
|
# @param [String] transit_routing_preference Specifies preferences for transit
|
38
|
-
# requests. Valid values are
|
59
|
+
# requests. Valid values are `less_walking` or `fewer_transfers`.
|
39
60
|
#
|
40
|
-
# @return
|
41
|
-
def directions(origin
|
61
|
+
# @return [Array] Array of routes.
|
62
|
+
def directions(origin, destination,
|
42
63
|
mode: nil, waypoints: nil, alternatives: false, avoid: nil,
|
43
64
|
language: nil, units: nil, region: nil, departure_time: nil,
|
44
65
|
arrival_time: nil, optimize_waypoints: false, transit_mode: nil,
|
45
66
|
transit_routing_preference: nil)
|
46
67
|
|
47
68
|
params = {
|
48
|
-
origin:
|
49
|
-
destination:
|
69
|
+
origin: GoogleMapsService::Convert.waypoint(origin),
|
70
|
+
destination: GoogleMapsService::Convert.waypoint(destination)
|
50
71
|
}
|
51
72
|
|
52
73
|
params[:mode] = GoogleMapsService::Validator.travel_mode(mode) if mode
|
53
74
|
|
54
|
-
if waypoints
|
75
|
+
if waypoints = waypoints
|
55
76
|
waypoints = GoogleMapsService::Convert.as_list(waypoints)
|
56
|
-
waypoints = waypoints.map { |waypoint|
|
57
|
-
waypoints = [
|
77
|
+
waypoints = waypoints.map { |waypoint| GoogleMapsService::Convert.waypoint(waypoint) }
|
78
|
+
waypoints = ['optimize:true'] + waypoints if optimize_waypoints
|
58
79
|
|
59
80
|
params[:waypoints] = GoogleMapsService::Convert.join_list("|", waypoints)
|
60
81
|
end
|
@@ -76,13 +97,5 @@ module GoogleMapsService
|
|
76
97
|
|
77
98
|
return get('/maps/api/directions/json', params)[:routes]
|
78
99
|
end
|
79
|
-
|
80
|
-
private
|
81
|
-
def _convert_waypoint(waypoint)
|
82
|
-
if waypoint.kind_of?(String)
|
83
|
-
return waypoint
|
84
|
-
end
|
85
|
-
return GoogleMapsService::Convert.latlng(waypoint)
|
86
|
-
end
|
87
100
|
end
|
88
101
|
end
|
@@ -1,45 +1,64 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../validator'
|
2
2
|
|
3
|
-
module GoogleMapsService
|
3
|
+
module GoogleMapsService::Apis
|
4
4
|
|
5
5
|
# Performs requests to the Google Maps Distance Matrix API.
|
6
6
|
module DistanceMatrix
|
7
7
|
|
8
8
|
# Gets travel distance and time for a matrix of origins and destinations.
|
9
9
|
#
|
10
|
-
# @
|
10
|
+
# @example Simple distance matrix
|
11
|
+
# origins = ["Perth, Australia", "Sydney, Australia",
|
12
|
+
# "Melbourne, Australia", "Adelaide, Australia",
|
13
|
+
# "Brisbane, Australia", "Darwin, Australia",
|
14
|
+
# "Hobart, Australia", "Canberra, Australia"]
|
15
|
+
# destinations = ["Uluru, Australia",
|
16
|
+
# "Kakadu, Australia",
|
17
|
+
# "Blue Mountains, Australia",
|
18
|
+
# "Bungle Bungles, Australia",
|
19
|
+
# "The Pinnacles, Australia"]
|
20
|
+
# matrix = client.distance_matrix(origins, destinations)
|
21
|
+
#
|
22
|
+
# @example Complex distance matrix
|
23
|
+
# origins = ["Bobcaygeon ON", [41.43206, -81.38992]]
|
24
|
+
# destinations = [[43.012486, -83.6964149], {lat: 42.8863855, lng: -78.8781627}]
|
25
|
+
# matrix = client.distance_matrix(origins, destinations,
|
26
|
+
# mode: 'driving',
|
27
|
+
# language: 'en-AU',
|
28
|
+
# avoid: 'tolls',
|
29
|
+
# units: 'imperial')
|
30
|
+
#
|
31
|
+
# @param [Array] origins One or more addresses and/or lat/lon pairs,
|
11
32
|
# from which to calculate distance and time. If you pass an address
|
12
33
|
# as a string, the service will geocode the string and convert it to
|
13
|
-
# a
|
14
|
-
# @param [Array
|
34
|
+
# a lat/lon coordinate to calculate directions.
|
35
|
+
# @param [Array] destinations One or more addresses and/or lat/lon pairs, to
|
15
36
|
# which to calculate distance and time. If you pass an address as a
|
16
37
|
# string, the service will geocode the string and convert it to a
|
17
|
-
#
|
38
|
+
# lat/lon coordinate to calculate directions.
|
18
39
|
# @param [String] mode Specifies the mode of transport to use when calculating
|
19
|
-
# directions. Valid values are
|
20
|
-
# "bicycling".
|
40
|
+
# directions. Valid values are `driving`, `walking`, `transit` or `bicycling`.
|
21
41
|
# @param [String] language The language in which to return results.
|
22
42
|
# @param [String] avoid Indicates that the calculated route(s) should avoid the
|
23
|
-
# indicated features. Valid values are
|
43
|
+
# indicated features. Valid values are `tolls`, `highways` or `ferries`.
|
24
44
|
# @param [String] units Specifies the unit system to use when displaying results.
|
25
|
-
# Valid values are
|
45
|
+
# Valid values are `metric` or `imperial`.
|
26
46
|
# @param [Integer, DateTime] departure_time Specifies the desired time of departure.
|
27
47
|
# @param [Integer, DateTime] arrival_time Specifies the desired time of arrival for transit
|
28
|
-
# directions. Note: you can
|
29
|
-
# arrival_time.
|
48
|
+
# directions. Note: you can not specify both `departure_time` and `arrival_time`.
|
30
49
|
# @param [String, Array<String>] transit_mode Specifies one or more preferred modes of transit.
|
31
50
|
# This parameter may only be specified for requests where the mode is
|
32
|
-
# transit. Valid values are
|
33
|
-
#
|
51
|
+
# transit. Valid values are `bus`, `subway`, `train`, `tram`, or `rail`.
|
52
|
+
# `rail` is equivalent to `["train", "tram", "subway"]`.
|
34
53
|
# @param [String] transit_routing_preference Specifies preferences for transit
|
35
|
-
# requests. Valid values are
|
54
|
+
# requests. Valid values are `less_walking` or `fewer_transfers`.
|
36
55
|
#
|
37
|
-
# @return
|
56
|
+
# @return [Hash] Matrix of distances. Results are returned in rows, each row
|
38
57
|
# containing one origin paired with each destination.
|
39
|
-
def distance_matrix(origins
|
40
|
-
|
41
|
-
|
42
|
-
|
58
|
+
def distance_matrix(origins, destinations,
|
59
|
+
mode: nil, language: nil, avoid: nil, units: nil,
|
60
|
+
departure_time: nil, arrival_time: nil, transit_mode: nil,
|
61
|
+
transit_routing_preference: nil)
|
43
62
|
params = {
|
44
63
|
origins: GoogleMapsService::Convert.waypoints(origins),
|
45
64
|
destinations: GoogleMapsService::Convert.waypoints(destinations)
|
@@ -57,7 +76,7 @@ module GoogleMapsService
|
|
57
76
|
raise ArgumentError, 'Should not specify both departure_time and arrival_time.'
|
58
77
|
end
|
59
78
|
|
60
|
-
params[:transit_mode] = GoogleMapsService::Convert.join_list(
|
79
|
+
params[:transit_mode] = GoogleMapsService::Convert.join_list('|', transit_mode) if transit_mode
|
61
80
|
params[:transit_routing_preference] = transit_routing_preference if transit_routing_preference
|
62
81
|
|
63
82
|
return get('/maps/api/distancematrix/json', params)
|
@@ -1,43 +1,50 @@
|
|
1
|
-
module GoogleMapsService
|
1
|
+
module GoogleMapsService::Apis
|
2
2
|
|
3
3
|
# Performs requests to the Google Maps Elevation API.
|
4
4
|
module Elevation
|
5
5
|
|
6
6
|
# Provides elevation data for locations provided on the surface of the
|
7
7
|
# earth, including depth locations on the ocean floor (which return negative
|
8
|
-
# values)
|
8
|
+
# values).
|
9
|
+
#
|
10
|
+
# @example Single point elevation
|
11
|
+
# results = client.elevation({latitude: 40.714728, longitude: -73.998672})
|
12
|
+
#
|
13
|
+
# @example Multiple points elevation
|
14
|
+
# locations = [[40.714728, -73.998672], [-34.397, 150.644]]
|
15
|
+
# results = client.elevation(locations)
|
9
16
|
#
|
10
17
|
# @param [Array] locations A single latitude/longitude hash, or an array of
|
11
18
|
# latitude/longitude hash from which you wish to calculate
|
12
19
|
# elevation data.
|
13
20
|
#
|
14
21
|
# @return [Array] Array of elevation data responses
|
15
|
-
def elevation(locations
|
16
|
-
params = {
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
params[:locations] = _convert_locations(locations)
|
22
|
+
def elevation(locations)
|
23
|
+
params = {
|
24
|
+
locations: GoogleMapsService::Convert.waypoints(locations)
|
25
|
+
}
|
22
26
|
|
23
|
-
return get(
|
27
|
+
return get('/maps/api/elevation/json', params)[:results]
|
24
28
|
end
|
25
29
|
|
26
30
|
# Provides elevation data sampled along a path on the surface of the earth.
|
27
31
|
#
|
32
|
+
# @example Elevation along path
|
33
|
+
# locations = [[40.714728, -73.998672], [-34.397, 150.644]]
|
34
|
+
# results = client.elevation_along_path(locations, 5)
|
35
|
+
#
|
28
36
|
# @param [String, Array] path A encoded polyline string, or a list of
|
29
|
-
# latitude/longitude
|
37
|
+
# latitude/longitude pairs from which you wish to calculate
|
30
38
|
# elevation data.
|
31
|
-
#
|
32
39
|
# @param [Integer] samples The number of sample points along a path for which to
|
33
40
|
# return elevation data.
|
34
41
|
#
|
35
42
|
# @return [Array] Array of elevation data responses
|
36
|
-
def elevation_along_path(path
|
43
|
+
def elevation_along_path(path, samples)
|
37
44
|
if path.kind_of?(String)
|
38
45
|
path = "enc:%s" % path
|
39
46
|
else
|
40
|
-
path =
|
47
|
+
path = GoogleMapsService::Convert.waypoints(path)
|
41
48
|
end
|
42
49
|
|
43
50
|
params = {
|
@@ -45,13 +52,7 @@ module GoogleMapsService
|
|
45
52
|
samples: samples
|
46
53
|
}
|
47
54
|
|
48
|
-
return get(
|
55
|
+
return get('/maps/api/elevation/json', params)[:results]
|
49
56
|
end
|
50
|
-
|
51
|
-
private
|
52
|
-
def _convert_locations(locations)
|
53
|
-
locations = GoogleMapsService::Convert.as_list(locations)
|
54
|
-
return GoogleMapsService::Convert.join_list("|", locations.map { |k| k.kind_of?(String) ? k : GoogleMapsService::Convert.latlng(k) })
|
55
|
-
end
|
56
57
|
end
|
57
58
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'google_maps_service/convert'
|
2
|
+
|
3
|
+
module GoogleMapsService::Apis
|
4
|
+
|
5
|
+
# Performs requests to the Google Maps Geocoding API.
|
6
|
+
module Geocoding
|
7
|
+
|
8
|
+
# Geocoding is the process of converting addresses
|
9
|
+
# (like `"1600 Amphitheatre Parkway, Mountain View, CA"`) into geographic
|
10
|
+
# coordinates (like latitude 37.423021 and longitude -122.083739), which you
|
11
|
+
# can use to place markers or position the map.
|
12
|
+
#
|
13
|
+
# @example Geocode an address
|
14
|
+
# results = client.geocode('Sydney')
|
15
|
+
#
|
16
|
+
# @example Geocode a component only
|
17
|
+
# results = client.geocode(nil, components: {administrative_area: 'TX', country: 'US'})
|
18
|
+
#
|
19
|
+
# @example Geocode an address and component
|
20
|
+
# results = client.geocode('Sydney', components: {administrative_area: 'TX', country: 'US'})
|
21
|
+
#
|
22
|
+
# @example Multiple parameters
|
23
|
+
# results = client.geocode('Sydney',
|
24
|
+
# components: {administrative_area: 'TX', country: 'US'},
|
25
|
+
# bounds: {
|
26
|
+
# northeast: {lat: 32.7183997, lng: -97.26864001970849},
|
27
|
+
# southwest: {lat: 32.7052583, lng: -97.27133798029149}
|
28
|
+
# },
|
29
|
+
# region: 'us')
|
30
|
+
#
|
31
|
+
# @param [String] address The address to geocode. You must specify either this value and/or `components`.
|
32
|
+
# @param [Hash] components A component filter for which you wish to obtain a geocode,
|
33
|
+
# for example: `{'administrative_area': 'TX','country': 'US'}`
|
34
|
+
# @param [String, Hash] bounds The bounding box of the viewport within which to bias geocode
|
35
|
+
# results more prominently. Accept string or hash with `northeast` and `southwest` keys.
|
36
|
+
# @param [String] region The region code, specified as a ccTLD (_top-level domain_)
|
37
|
+
# two-character value.
|
38
|
+
# @param [String] language The language in which to return results.
|
39
|
+
#
|
40
|
+
# @return [Array] Array of geocoding results.
|
41
|
+
def geocode(address, components: nil, bounds: nil, region: nil, language: nil)
|
42
|
+
params = {}
|
43
|
+
|
44
|
+
params[:address] = address if address
|
45
|
+
params[:components] = GoogleMapsService::Convert.components(components) if components
|
46
|
+
params[:bounds] = GoogleMapsService::Convert.bounds(bounds) if bounds
|
47
|
+
params[:region] = region if region
|
48
|
+
params[:language] = language if language
|
49
|
+
|
50
|
+
return get('/maps/api/geocode/json', params)[:results]
|
51
|
+
end
|
52
|
+
|
53
|
+
# Reverse geocoding is the process of converting geographic coordinates into a
|
54
|
+
# human-readable address.
|
55
|
+
#
|
56
|
+
# @example Simple lat/lon pair
|
57
|
+
# client.reverse_geocode({lat: 40.714224, lng: -73.961452})
|
58
|
+
#
|
59
|
+
# @example Multiple parameters
|
60
|
+
# client.reverse_geocode([40.714224, -73.961452],
|
61
|
+
# location_type: ['ROOFTOP', 'RANGE_INTERPOLATED'],
|
62
|
+
# result_type: ['street_address', 'route'],
|
63
|
+
# language: 'es')
|
64
|
+
#
|
65
|
+
# @param [Hash, Array] latlng The latitude/longitude value for which you wish to obtain
|
66
|
+
# the closest, human-readable address.
|
67
|
+
# @param [String, Array<String>] location_type One or more location types to restrict results to.
|
68
|
+
# @param [String, Array<String>] result_type One or more address types to restrict results to.
|
69
|
+
# @param [String] language The language in which to return results.
|
70
|
+
#
|
71
|
+
# @return [Array] Array of reverse geocoding results.
|
72
|
+
def reverse_geocode(latlng, location_type: nil, result_type: nil, language: nil)
|
73
|
+
params = {
|
74
|
+
latlng: GoogleMapsService::Convert.latlng(latlng)
|
75
|
+
}
|
76
|
+
|
77
|
+
params[:result_type] = GoogleMapsService::Convert.join_list('|', result_type) if result_type
|
78
|
+
params[:location_type] = GoogleMapsService::Convert.join_list('|', location_type) if location_type
|
79
|
+
params[:language] = language if language
|
80
|
+
|
81
|
+
return get('/maps/api/geocode/json', params)[:results]
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|