![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
gem install google-maps
Or add the following line to your Gemfile:
gem 'google-maps'
You can either authenticate with an API key or a digital signature.
API key:
Google::Maps.configure do |config|
config.authentication_mode = Google::Maps::Configuration::API_KEY
config.api_key = 'xxxxxxxxxxx'
end
Digital signature:
Google::Maps.configure do |config|
config.authentication_mode = Google::Maps::Configuration::DIGITAL_SIGNATURE
config.client_id = 'xxxxxxxxxxx'
config.client_secret = 'xxxxxxxxxxx'
end
Set the default language.
Google::Maps.configure do |config|
config.default_language = :nl #dutch
end
Google::Maps.distance("Science Park, Amsterdam", "Deventer")
#=> "105 km"
Google::Maps.distance("52.3545543,4.9519029", "Deventer")
#=> "105 km"
Google::Maps.duration("Science Park, Amsterdam", "Deventer")
#=> "1 hour 12 mins"
Google::Maps.duration("52.3545543,4.9519029", "Deventer")
#=> "1 hour 12 mins"
Google::Maps.distance_matrix("Science Park, Amsterdam", "Deventer").distance
#=> 104478
Google::Maps.distance_matrix("Science Park, Amsterdam", "Deventer").duration
#=> 4374
route = Google::Maps.route("Science Park, Amsterdam", "Deventer")
route = Google::Maps.route("52.3545543,4.9519029", "Deventer")
route.distance.text
#=> "104 km"
route.duration.text
#=> "1 hour 12 mins"
route.distance.value
#=> 103712
route.duration.value
#=> 4337
route.steps
#=> [
{
"distance" => {
"text" => "0,1 km",
"value" => 125
},
"duration" => {
"text" => "1 min.",
"value" => 35
},
"end_location" => {
"lat" => 52.3556768,
"lng" => 4.9545739
},
"html_instructions" => "Rijd <b>naar het noordwesten</b>, richting het <b>Science Park</b>",
"polyline" => {
"points" => "oqp~Hqpf]?@?@?@KNOVEHA@A?s@wAQ]Q_@We@?A?ADI"
},
"start_location" => {
"lat" => 52.3549602,
"lng" => 4.9538473
},
"travel_mode" => "DRIVING"
},
{
"distance" => {
"text" => "37 m",
........
The distance, duration and route methods allow you to pass an options hash to the Directions API. All options can also be set as default_params for these services.
Google::Maps.configure do |config|
...
config.default_params = {
directions_service: {
mode: 'transit',
transit_routing_preference: 'fewer_transfers'
}
}
...
end
The following options are permitted:
{
mode: 'driving', #default
transit_mode: 'train', #only used when mode is set to 'transit'
transit_routing_preference: 'fewer_transfers',
avoid: 'tolls',
arrival_time: 1545397430, # In seconds since midnight, January 1, 1970 UTC.
departure_time: 1545397430, # Cannot be in the past.
}
# NB! You can specify either departure_time or arrival_time, but not both.
TRAVEL_MODES = [
'driving', #(Default) indicates standard driving directions using the road network.
'bicycling', #requests bicycling directions via bicycle paths & preferred streets.
'transit', #requests directions via public transit routes.
'walking'
]
TRANSIT_MODES = [
'bus',
'subway',
'train',
'tram',
'rail' # This is equivalent to transit_mode=train|tram|subway
]
TRANSIT_ROUTING_PREFERENCES = [
'less_walking', prefer limited amounts of walking.
'fewer_transfers' prefer a limited number of transfers.
]
AVOID = [
'tolls',
'highways',
'ferries',
'indoor', # Avoid indoor steps for walking and transit directions.
]
places = Google::Maps.places('Amsterdam')
places.first.text
#=> "Amsterdam, Nederland"
places.first.place_id
#=> "ChIJVXealLU_xkcRja_At0z9AGY"
place = Google::Maps.place("ChIJVXealLU_xkcRja_At0z9AGY")
place.place_id
#=> "ChIJVXealLU_xkcRja_At0z9AGY"
place.latitude
#=> "52.3679843"
place.longitude
#=> "4.9035614"
place.address
#=> "Amsterdam, Nederland"
place.name
#=> "Amsterdam"
place.photos
#<Google::Maps::Result height, html_attribution[], photo_reference, width>
place.website
#=> "http://www.amsterdam.nl/"
place.url
#=> "https://maps.google.com/?q=Amsterdam,+Netherlands"
geocodes = Google::Maps.geocode("Science Park, Amsterdam")
geocodes.first.address = "Science Park, 1012 WX Amsterdam, Nederland"
geocodes.first.latitude = 52.3545543
geocodes.first.longitude = 4.9540916
Run all tests:
rspec spec/
Copyright (c) 2011-2019 Zilverline. See LICENSE for details.
FAQs
Unknown package
We found that google-maps demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.