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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb00f53441211719da0e59680a1186a109615495
|
4
|
+
data.tar.gz: 6075646a6a52b3cd64abce441479b1f80e967cbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0007fe257d673c7011097aefc8436664e3a450c7cb9a26d772b5ef72b6818ac52342614572fcf014f5f433ee0ef6ee17a7c2fed98b307d685d3b1807ca8662e
|
7
|
+
data.tar.gz: 24a6947fc3683cd5e58886376bc293a3c3c395952cb021435e001b2c2c4dab3131cace9191c99b999a353fd391667e92cda0b053b4b2dd06d73125a38790acda
|
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.4.0
|
4
|
+
|
5
|
+
* Use required positional and optional named parameters (_breaking changes_)
|
6
|
+
* Documentation with examples
|
7
|
+
* Documentation using markdown syntax
|
8
|
+
* Use OpenSSL instead Ruby-HMAC to sign url
|
9
|
+
* Customizeable HTTP client
|
10
|
+
* Fix QPS bug: ensure number of queue items is the given value
|
11
|
+
|
12
|
+
## 0.3.0
|
13
|
+
|
14
|
+
* QPS: Query per second
|
15
|
+
* Refactor lib
|
16
|
+
|
17
|
+
## 0.2.0
|
18
|
+
|
19
|
+
* Support Ruby >= 2.0.0
|
20
|
+
* Auto-retry connection when the request is failed and possible
|
21
|
+
* Restructure test (rspec) directory
|
22
|
+
* Refactor lib
|
23
|
+
|
24
|
+
## 0.1.0
|
25
|
+
|
26
|
+
* Initial release.
|
27
|
+
* Support Ruby >= 2.2
|
28
|
+
* [Google Maps Web Service API](https://developers.google.com/maps/documentation/webservices/) scope:
|
29
|
+
- [Directions API](https://developers.google.com/maps/documentation/directions/)
|
30
|
+
- [Distance Matrix API](https://developers.google.com/maps/documentation/distancematrix/)
|
31
|
+
- [Elevation API](https://developers.google.com/maps/documentation/elevation/)
|
32
|
+
- [Geocoding API](https://developers.google.com/maps/documentation/geocoding/)
|
33
|
+
- [Time Zone API](https://developers.google.com/maps/documentation/timezone/)
|
34
|
+
- [Roads API](https://developers.google.com/maps/documentation/roads/)
|
data/README.md
CHANGED
@@ -1,47 +1,59 @@
|
|
1
|
-
# Ruby
|
1
|
+
# Ruby gem for Google Maps APIs
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/google_maps_service.svg)](http://badge.fury.io/rb/google_maps_service) [![Build Status](https://travis-ci.org/edwardsamuel/google-maps-services-ruby.svg?branch=master)](https://travis-ci.org/edwardsamuel/google-maps-services-ruby) [![Dependency Status](https://gemnasium.com/edwardsamuel/google-maps-services-ruby.svg)](https://gemnasium.com/edwardsamuel/google-maps-services-ruby) [![Code Climate](https://codeclimate.com/github/edwardsamuel/google-maps-services-ruby/badges/gpa.svg)](https://codeclimate.com/github/edwardsamuel/google-maps-services-ruby) [![Coverage Status](https://coveralls.io/repos/edwardsamuel/google-maps-services-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/edwardsamuel/google-maps-services-ruby?branch=master)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/google_maps_service.svg)](http://badge.fury.io/rb/google_maps_service) [![Build Status](https://travis-ci.org/edwardsamuel/google-maps-services-ruby.svg?branch=master)](https://travis-ci.org/edwardsamuel/google-maps-services-ruby) [![Dependency Status](https://gemnasium.com/edwardsamuel/google-maps-services-ruby.svg)](https://gemnasium.com/edwardsamuel/google-maps-services-ruby) [![Code Climate](https://codeclimate.com/github/edwardsamuel/google-maps-services-ruby/badges/gpa.svg)](https://codeclimate.com/github/edwardsamuel/google-maps-services-ruby) [![Coverage Status](https://coveralls.io/repos/edwardsamuel/google-maps-services-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/edwardsamuel/google-maps-services-ruby?branch=master) [![Inch CI](https://inch-ci.org/github/edwardsamuel/google-maps-services-ruby.svg?branch=master)](https://inch-ci.org/github/edwardsamuel/google-maps-services-ruby?branch=master)
|
4
4
|
|
5
|
-
|
5
|
+
![Analytics](https://ga-beacon.appspot.com/UA-66926725-1/google-maps-services-ruby/readme?pixel)
|
6
|
+
|
7
|
+
*This gem is ported from [Python Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-python).*
|
6
8
|
|
7
9
|
## Description
|
8
10
|
|
9
11
|
Use Ruby? Want to [geocode][Geocoding API] something? Looking for [directions][Directions API]?
|
10
|
-
Maybe [matrices of directions][Distance Matrix API]? This
|
12
|
+
Maybe [matrices of directions][Distance Matrix API]? This gem brings the [Google Maps API Web
|
11
13
|
Services] to your Ruby application.
|
12
|
-
![Analytics](https://ga-beacon.appspot.com/UA-66926725-1/google-maps-services-ruby/readme?pixel)
|
13
14
|
|
14
|
-
The Ruby
|
15
|
+
The Ruby gem for Google Maps Web Service APIs is a gem for the following Google Maps APIs:
|
15
16
|
|
16
|
-
- [Directions API]
|
17
|
-
- [Distance Matrix API]
|
18
|
-
- [Elevation API]
|
19
|
-
- [Geocoding API]
|
20
|
-
- [Time Zone API]
|
21
|
-
- [Roads API]
|
17
|
+
- [Google Maps Directions API][Directions API]
|
18
|
+
- [Google Maps Distance Matrix API][Distance Matrix API]
|
19
|
+
- [Google Maps Elevation API][Elevation API]
|
20
|
+
- [Google Maps Geocoding API][Geocoding API]
|
21
|
+
- [Google Maps Time Zone API][Time Zone API]
|
22
|
+
- [Google Maps Roads API][Roads API]
|
22
23
|
|
23
24
|
Keep in mind that the same [terms and conditions](https://developers.google.com/maps/terms) apply
|
24
|
-
to usage of the APIs when they're accessed through this
|
25
|
+
to usage of the APIs when they're accessed through this gem.
|
25
26
|
|
26
|
-
## Support
|
27
27
|
|
28
|
-
|
29
|
-
the library that we want you to build real production applications on it. We will try to support,
|
30
|
-
through Stack Overflow, the public and protected surface of the library and maintain backwards
|
31
|
-
compatibility in the future; however, while the library is in version 0.x, we reserve the right
|
32
|
-
to make backwards-incompatible changes. If we do remove some functionality (typically because
|
33
|
-
better functionality exists or if the feature proved infeasible), our intention is to deprecate
|
34
|
-
and give developers a year to update their code.
|
28
|
+
## Features
|
35
29
|
|
36
|
-
|
37
|
-
|
30
|
+
### Rate Limiting
|
31
|
+
|
32
|
+
Never sleep between requests again! By default, requests are sent at the expected rate limits for
|
33
|
+
each web service, typically 10 queries per second for free users. If you want to speed up or slowdown requests, you can do that too, using `queries_per_second` options while initializing API client.
|
34
|
+
|
35
|
+
### Retry on Failure
|
36
|
+
|
37
|
+
Automatically retry when intermittent failures occur. That is, when any of the retriable 5xx errors
|
38
|
+
are returned from the API.
|
39
|
+
|
40
|
+
### Keys *and* Client IDs
|
41
|
+
|
42
|
+
Maps API for Work customers can use their [client ID and secret][clientid] to authenticate. Free
|
43
|
+
customers can use their [API key][apikey], too.
|
44
|
+
|
45
|
+
Note: Currently, [Roads API] does not accept client ID. It requires API key to authenticate the request.
|
46
|
+
|
47
|
+
### Ruby Hash/Array as API Result
|
48
|
+
|
49
|
+
This gem return a Ruby Hash/Array object as the API result. The result format structure is same as in Google Maps API documentation.
|
38
50
|
|
39
51
|
## Requirements
|
40
52
|
|
41
53
|
- Ruby 2.0 or later.
|
42
|
-
- A Google Maps API
|
54
|
+
- A Google Maps API credentials (API keys or client IDs)
|
43
55
|
|
44
|
-
### API keys
|
56
|
+
### Obtain API keys
|
45
57
|
|
46
58
|
Each Google Maps Web Service requires an API key or Client ID. API keys are
|
47
59
|
freely available with a Google Account at https://developers.google.com/console.
|
@@ -72,58 +84,287 @@ Your API key should be 40 characters long, and begin with `AIza`.
|
|
72
84
|
|
73
85
|
## Installation
|
74
86
|
|
75
|
-
|
87
|
+
Add this line to your application's Gemfile:
|
88
|
+
|
89
|
+
gem 'google_maps_service'
|
90
|
+
|
91
|
+
And then execute:
|
76
92
|
|
77
|
-
|
93
|
+
bundle install
|
78
94
|
|
79
|
-
|
95
|
+
Or install it yourself as:
|
80
96
|
|
81
|
-
|
82
|
-
https://developers.google.com/maps/.
|
97
|
+
gem install google_maps_service
|
83
98
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
- [Geocoding API]
|
88
|
-
- [Time Zone API]
|
89
|
-
- [Roads API]
|
99
|
+
In your Ruby code, add this line to load this gem:
|
100
|
+
|
101
|
+
require 'google_maps_service'
|
90
102
|
|
91
103
|
## Usage
|
92
104
|
|
93
|
-
|
105
|
+
Before you request Google Maps API, you must configure the client.
|
106
|
+
|
107
|
+
You can view the [reference documentation](http://www.rubydoc.info/gems/google_maps_service).
|
108
|
+
|
109
|
+
### Configure client
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
require 'google_maps_service'
|
113
|
+
|
114
|
+
# Setup API keys
|
115
|
+
gmaps = GoogleMapsService::Client.new(key: 'Add your key here')
|
116
|
+
|
117
|
+
# Setup client IDs
|
118
|
+
gmaps = GoogleMapsService::Client.new(
|
119
|
+
client_id: 'Add your client id here',
|
120
|
+
client_secret: 'Add your client secret here'
|
121
|
+
)
|
122
|
+
|
123
|
+
# More complex setup
|
124
|
+
gmaps = GoogleMapsService::Client.new(
|
125
|
+
key: 'Add your key here',
|
126
|
+
retry_timeout: 20, # Timeout for retrying failed request
|
127
|
+
queries_per_second: 10 # Limit total request per second
|
128
|
+
)
|
129
|
+
```
|
130
|
+
You can also set up the client globally.
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
require 'google_maps_service'
|
134
|
+
|
135
|
+
# Setup global parameters
|
136
|
+
GoogleMapsService.configure do |config|
|
137
|
+
config.key = 'Add your key here'
|
138
|
+
config.retry_timeout = 20
|
139
|
+
config.queries_per_second = 10
|
140
|
+
end
|
141
|
+
|
142
|
+
# Initialize client using global parameters
|
143
|
+
gmaps = GoogleMapsService::Client.new
|
144
|
+
```
|
145
|
+
|
146
|
+
For more examples and detail (setup **proxy**, **timeout**, **caching**, etc.) while initializing the client, check out [Client documentation](http://www.rubydoc.info/gems/google_maps_service/GoogleMapsService/Apis/Client#initialize-instance_method).
|
147
|
+
|
148
|
+
### Latitude/longitude pairs format
|
149
|
+
|
150
|
+
Some APIs require latitude/longitude pair(s) as their parameter(s). This gem accept various format of latitude/longitude pairs:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
# Array
|
154
|
+
latlng = [40.714224, -73.961452]
|
155
|
+
|
156
|
+
# Hash with symbolized keys
|
157
|
+
latlng = {lat: 40.714224, lng: -73.961452}
|
158
|
+
latlng = {latitude: 40.714224, longitude: -73.961452}
|
159
|
+
|
160
|
+
# Hash with string keys
|
161
|
+
latlng = {'lat' => 40.714224, 'lng' => -73.961452}
|
162
|
+
latlng = {'latitude' => 40.714224, 'longitude' => -73.961452}
|
163
|
+
```
|
164
|
+
|
165
|
+
### Directions API
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
# Simple directions
|
169
|
+
routes = gmaps.directions(
|
170
|
+
'1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA',
|
171
|
+
'2400 Amphitheatre Parkway, Mountain View, CA 94043, USA',
|
172
|
+
mode: 'walking',
|
173
|
+
alternatives: false)
|
174
|
+
```
|
175
|
+
|
176
|
+
Sample result:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
[{
|
180
|
+
:bounds=>{
|
181
|
+
:northeast=>{:lat=>37.4238004, :lng=>-122.084314},
|
182
|
+
:southwest=>{:lat=>37.42277989999999, :lng=>-122.0882019}
|
183
|
+
},
|
184
|
+
:copyrights=>"Map data ©2015 Google",
|
185
|
+
:legs=>[
|
186
|
+
{
|
187
|
+
:distance=>{:text=>"0.2 mi", :value=>393},
|
188
|
+
:duration=>{:text=>"5 mins", :value=>287},
|
189
|
+
:end_address=>"2400 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
|
190
|
+
:end_location=>{:lat=>37.4238004, :lng=>-122.0882019},
|
191
|
+
:start_address=>"1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
|
192
|
+
:start_location=>{:lat=>37.42277989999999, :lng=>-122.084314},
|
193
|
+
:steps=>[
|
194
|
+
{
|
195
|
+
:distance=>{:text=>"223 ft", :value=>68},
|
196
|
+
:duration=>{:text=>"1 min", :value=>49},
|
197
|
+
:end_location=>{:lat=>37.4228653, :lng=>-122.0850785},
|
198
|
+
:html_instructions=>"Head <b>west</b>",
|
199
|
+
:polyline=>{:points=>"kclcF|qchVEdAGx@ALAJ"},
|
200
|
+
:start_location=>{:lat=>37.42277989999999, :lng=>-122.084314},
|
201
|
+
:travel_mode=>"WALKING"
|
202
|
+
}, {
|
203
|
+
:distance=>{:text=>"108 ft", :value=>33},
|
204
|
+
:duration=>{:text=>"1 min", :value=>23},
|
205
|
+
:end_location=>{:lat=>37.423161, :lng=>-122.0850102},
|
206
|
+
:html_instructions=>"Turn <b>right</b> toward <b>Amphitheatre Pkwy</b>",
|
207
|
+
:maneuver=>"turn-right",
|
208
|
+
:polyline=>{:points=>"}clcFvvchVg@IQC"},
|
209
|
+
:start_location=>{:lat=>37.4228653, :lng=>-122.0850785},
|
210
|
+
:travel_mode=>"WALKING"
|
211
|
+
}, {
|
212
|
+
:distance=>{:text=>"407 ft", :value=>124},
|
213
|
+
:duration=>{:text=>"2 mins", :value=>90},
|
214
|
+
:end_location=>{:lat=>37.423396, :lng=>-122.0863768},
|
215
|
+
:html_instructions=>"Turn <b>left</b> onto <b>Amphitheatre Pkwy</b>",
|
216
|
+
:maneuver=>"turn-left",
|
217
|
+
:polyline=>{:points=>"welcFhvchVEf@Eb@C\\EZGp@Il@CRAJAJ"},
|
218
|
+
:start_location=>{:lat=>37.423161, :lng=>-122.0850102},
|
219
|
+
:travel_mode=>"WALKING"
|
220
|
+
}, {
|
221
|
+
:distance=>{:text=>"0.1 mi", :value=>168},
|
222
|
+
:duration=>{:text=>"2 mins", :value=>125},
|
223
|
+
:end_location=>{:lat=>37.4238004, :lng=>-122.0882019},
|
224
|
+
:html_instructions=>
|
225
|
+
"Slight <b>right</b> to stay on <b>Amphitheatre Pkwy</b><div style=\"font-size:0.9em\">Destination will be on the right</div>",
|
226
|
+
:maneuver=>"turn-slight-right",
|
227
|
+
:polyline=>{:points=>"gglcFz~chVGJADAD?DIh@MhAWhBOxACT"},
|
228
|
+
:start_location=>{:lat=>37.423396, :lng=>-122.0863768},
|
229
|
+
:travel_mode=>"WALKING"
|
230
|
+
}
|
231
|
+
],
|
232
|
+
:via_waypoint=>[]
|
233
|
+
}
|
234
|
+
],
|
235
|
+
:overview_polyline=>{:points=>"kclcF|qchVQxCy@MKjA[xCE^IVMz@y@bH"},
|
236
|
+
:summary=>"Amphitheatre Pkwy",
|
237
|
+
:warnings=>["Walking directions are in beta. Use caution – This route may be missing sidewalks or pedestrian paths."],
|
238
|
+
:waypoint_order=>[]
|
239
|
+
}]
|
240
|
+
```
|
241
|
+
|
242
|
+
For more usage examples and result format, check out [gem documentation](http://www.rubydoc.info/gems/google_maps_service/GoogleMapsService/Apis/Directions), [test script](https://github.com/edwardsamuel/google-maps-services-ruby/tree/master/spec/google_maps_service/apis/directions_spec.rb), and [Google Maps Directions API documentation][Directions API].
|
243
|
+
|
244
|
+
### Distance Matrix API
|
245
|
+
|
246
|
+
```ruby
|
247
|
+
# Multiple parameters distance matrix
|
248
|
+
origins = ["Bobcaygeon ON", [41.43206, -81.38992]]
|
249
|
+
destinations = [[43.012486, -83.6964149], {lat: 42.8863855, lng: -78.8781627}]
|
250
|
+
matrix = gmaps.distance_matrix(origins, destinations,
|
251
|
+
mode: 'driving',
|
252
|
+
language: 'en-AU',
|
253
|
+
avoid: 'tolls',
|
254
|
+
units: 'imperial')
|
255
|
+
```
|
256
|
+
|
257
|
+
For more usage examples and result format, check out [gem documentation](http://www.rubydoc.info/gems/google_maps_service/GoogleMapsService/Apis/DistanceMatrix), [test script](https://github.com/edwardsamuel/google-maps-services-ruby/tree/master/spec/google_maps_service/apis/distance_matrix_spec.rb), and [Google Maps Distance Matrix API documentation][Distance Matrix API].
|
258
|
+
|
259
|
+
### Elevation API
|
94
260
|
|
95
261
|
```ruby
|
96
|
-
|
262
|
+
# Elevation of some locations
|
263
|
+
locations = [[40.714728, -73.998672], [-34.397, 150.644]]
|
264
|
+
results = gmaps.elevation(locations)
|
265
|
+
|
266
|
+
# Elevation along path
|
267
|
+
locations = [[40.714728, -73.998672], [-34.397, 150.644]]
|
268
|
+
results = gmaps.elevation_along_path(locations, 5)
|
269
|
+
```
|
270
|
+
|
271
|
+
For more usage examples and result format, check out [gem documentation](http://www.rubydoc.info/gems/google_maps_service/GoogleMapsService/Apis/Elevation), [test script](https://github.com/edwardsamuel/google-maps-services-ruby/tree/master/spec/google_maps_service/apis/elevation_spec.rb), and [Google Maps Elevation API documentation][Elevation API].
|
97
272
|
|
98
|
-
|
99
|
-
|
273
|
+
### Geocoding API
|
274
|
+
|
275
|
+
```ruby
|
276
|
+
# Geocoding an address
|
277
|
+
results = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
|
100
278
|
|
101
279
|
# Look up an address with reverse geocoding
|
102
|
-
|
103
|
-
|
104
|
-
# Request directions via public transit
|
105
|
-
now = Time.now
|
106
|
-
directions_result = gmaps.directions(origin: "Sydney Town Hall",
|
107
|
-
destination: "Parramatta, NSW",
|
108
|
-
mode: "transit",
|
109
|
-
departure_time: now)
|
280
|
+
results = gmaps.reverse_geocode([40.714224, -73.961452])
|
110
281
|
```
|
111
282
|
|
112
|
-
For more usage examples, check out [
|
283
|
+
For more usage examples and result format, check out [gem documentation](http://www.rubydoc.info/gems/google_maps_service/GoogleMapsService/Apis/Geocoding), [test script](https://github.com/edwardsamuel/google-maps-services-ruby/tree/master/spec/google_maps_service/apis/geocoding_spec.rb), and [Google Maps Geocoding API documentation][Geocoding API].
|
113
284
|
|
114
|
-
|
285
|
+
### Roads API
|
286
|
+
|
287
|
+
```ruby
|
288
|
+
# Snap to roads
|
289
|
+
path = [
|
290
|
+
[-33.8671, 151.20714],
|
291
|
+
[-33.86708, 151.20683000000002],
|
292
|
+
[-33.867070000000005, 151.20674000000002],
|
293
|
+
[-33.86703, 151.20625]
|
294
|
+
]
|
295
|
+
results = gmaps.snap_to_roads(path, interpolate: true)
|
296
|
+
|
297
|
+
# Snapped speed limits
|
298
|
+
path = [
|
299
|
+
[-33.8671, 151.20714],
|
300
|
+
[-33.86708, 151.20683000000002],
|
301
|
+
[-33.867070000000005, 151.20674000000002],
|
302
|
+
[-33.86703, 151.20625]
|
303
|
+
]
|
304
|
+
results = gmaps.snapped_speed_limits(path)
|
305
|
+
|
306
|
+
# Speed limits
|
307
|
+
place_ids = [
|
308
|
+
'ChIJ0wawjUCuEmsRgfqC5Wd9ARM',
|
309
|
+
'ChIJ6cs2kkCuEmsRUfqC5Wd9ARM'
|
310
|
+
]
|
311
|
+
results = gmaps.speed_limits(place_ids)
|
312
|
+
```
|
313
|
+
|
314
|
+
For more usage examples and result format, check out [gem documentation](http://www.rubydoc.info/gems/google_maps_service/GoogleMapsService/Apis/Roads), [test script](https://github.com/edwardsamuel/google-maps-services-ruby/tree/master/spec/google_maps_service/apis/roads_spec.rb), and [Google Maps Roads API documentation][Roads API].
|
315
|
+
|
316
|
+
### Time Zone API
|
115
317
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
318
|
+
```ruby
|
319
|
+
# Current time zone
|
320
|
+
timezone = gmaps.timezone([39.603481, -119.682251])
|
321
|
+
|
322
|
+
# Time zone at certain time
|
323
|
+
timezone = gmaps.timezone([39.603481, -119.682251], timestamp: Time.at(1608))
|
324
|
+
```
|
325
|
+
|
326
|
+
For more usage examples and result format, check out [gem documentation](http://www.rubydoc.info/gems/google_maps_service/GoogleMapsService/Apis/TimeZone), [test script](https://github.com/edwardsamuel/google-maps-services-ruby/tree/master/spec/google_maps_service/apis/time_zone_spec.rb), and [Google Maps Time Zone API documentation][Time Zone API].
|
327
|
+
|
328
|
+
### Polyline encoder/decoder
|
329
|
+
|
330
|
+
[Google Encoded Polyline] is a lossy compression algorithm that allows you to store a series of coordinates as a single string. This format is used in some APIs:
|
331
|
+
|
332
|
+
- [Directions API] encodes the result path.
|
333
|
+
- [Elevation API] also accepts the encoded polyline as request parameter.
|
334
|
+
|
335
|
+
To handle Google Encoded Polyline, this gem provides encoder/decoder:
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
require 'google_maps_service/polyline' # Or, require 'google_maps_service' is enough
|
121
339
|
|
340
|
+
# Decode polyline
|
341
|
+
encoded_path = '_p~iF~ps|U_ulLnnqC_mqNvxq`@'
|
342
|
+
path = GoogleMapsService::Polyline.decode(encoded_path)
|
343
|
+
#=> [{:lat=>38.5, :lng=>-120.2}, {:lat=>40.7, :lng=>-120.95}, {:lat=>43.252, :lng=>-126.45300000000002}]
|
344
|
+
|
345
|
+
# Encode polyline
|
346
|
+
path = [[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]]
|
347
|
+
encoded_path = GoogleMapsService::Polyline.encode(path)
|
348
|
+
#=> "_p~iF~ps|U_ulLnnqC_mqNvxq`@"
|
349
|
+
```
|
350
|
+
|
351
|
+
## Issues and feature suggestions
|
352
|
+
|
353
|
+
If you find a bug, or have a feature suggestion, please [log an issue][issues]. If you'd like to
|
354
|
+
contribute, please read [How to Contribute](#contributing).
|
355
|
+
|
356
|
+
## Contributing
|
357
|
+
|
358
|
+
1. Fork it (https://github.com/edwardsamuel/google-maps-services-ruby/fork).
|
359
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
360
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
361
|
+
4. Push to the branch (`git push origin my-new-feature`).
|
362
|
+
5. Create a new Pull Request.
|
122
363
|
|
123
364
|
[apikey]: https://developers.google.com/maps/faq#keysystem
|
124
365
|
[clientid]: https://developers.google.com/maps/documentation/business/webservices/auth
|
125
366
|
|
126
|
-
[Google Maps API Web Services]: https://developers.google.com/maps/
|
367
|
+
[Google Maps API Web Services]: https://developers.google.com/maps/web-services/overview/
|
127
368
|
[Directions API]: https://developers.google.com/maps/documentation/directions/
|
128
369
|
[Distance Matrix API]: https://developers.google.com/maps/documentation/distancematrix/
|
129
370
|
[Elevation API]: https://developers.google.com/maps/documentation/elevation/
|
@@ -131,4 +372,6 @@ For more usage examples, check out [the tests](spec/).
|
|
131
372
|
[Time Zone API]: https://developers.google.com/maps/documentation/timezone/
|
132
373
|
[Roads API]: https://developers.google.com/maps/documentation/roads/
|
133
374
|
|
375
|
+
[Google Encoded Polyline]: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
|
376
|
+
|
134
377
|
[issues]: https://github.com/edwardsamuel/google-maps-services-ruby/issues
|