https://github.com/foveacentral/google_maps_geocoder
A simple PORO wrapper for geocoding with Google Maps
https://github.com/foveacentral/google_maps_geocoder
geocoder google-maps-api ruby
Last synced: 8 months ago
JSON representation
A simple PORO wrapper for geocoding with Google Maps
- Host: GitHub
- URL: https://github.com/foveacentral/google_maps_geocoder
- Owner: FoveaCentral
- License: mit
- Created: 2011-04-13T15:51:23.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2025-04-21T04:10:52.000Z (9 months ago)
- Last Synced: 2025-05-10T08:46:37.018Z (8 months ago)
- Topics: geocoder, google-maps-api, ruby
- Language: Ruby
- Homepage: https://www.rubydoc.info/gems/google_maps_geocoder
- Size: 210 KB
- Stars: 11
- Watchers: 3
- Forks: 8
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# GoogleMapsGeocoder
[](https://github.com/FoveaCentral/google_maps_geocoder/actions/workflows/test.yml)
[](https://codeclimate.com/github/FoveaCentral/google_maps_geocoder)
[](https://coveralls.io/github/FoveaCentral/google_maps_geocoder?branch=master)
[](https://www.bestpractices.dev/projects/92)
[](https://scorecard.dev/viewer/?uri=github.com/FoveaCentral/google_maps_geocoder)
[](https://rubygems.org/gems/google_maps_geocoder)
A simple Plain Old Ruby Object wrapper for geocoding with Google Maps, `GoogleMapsGeocoder` gives you all its geocoding functionality with these advantages:
* *easy to use* in **[only one step](#ready-to-go-in-one-step)**
* **[fully documented](https://www.rubydoc.info/gems/google_maps_geocoder)** with *[complete test coverage](https://coveralls.io/github/FoveaCentral/google_maps_geocoder)*
* *lightweight* at **[only 20.5 K](https://rubygems.org/gems/google_maps_geocoder)** as a gem (that's less than a quarter the size of [Geocoder](https://rubygems.org/gems/geocoder))
* only a **[single dependency](google_maps_geocoder.gemspec)**, the commonly used [Rack](https://github.com/rack/rack)
## Installation
1. Set your Google Maps API key, which Google now requires, as an environment variable:
```bash
export GOOGLE_MAPS_API_KEY=[your key]
```
2. Add `GoogleMapsGeocoder` to your Gemfile and run `bundle`:
```ruby
gem 'google_maps_geocoder'
```
Or try it out in `irb` with:
```ruby
require 'google_maps_geocoder'
```
### Security note
`GoogleMapsGeocoder` is cryptographically signed. To insure the gem you install hasn’t been tampered with, add my public key as a trusted certificate and then install:
```sh
gem cert --add <(curl -Ls https://raw.github.com/FoveaCentral/google_maps_geocoder/master/certs/ivanoblomov.pem)
gem install google_maps_geocoder -P HighSecurity
```
## Ready to Go in One Step
```ruby
chez_barack = GoogleMapsGeocoder.new 'White House'
```
## Usage
Get the complete, formatted address:
```ruby
chez_barack.formatted_address
=> "1600 Pennsylvania Avenue Northwest, President's Park, Washington, DC 20500, USA"
```
...standardized name of the city:
```ruby
chez_barack.city
=> "Washington"
```
...full name of the state or region:
```ruby
chez_barack.state_long_name
=> "District of Columbia"
```
...standard abbreviation for the state/region:
```ruby
chez_barack.state_short_name
=> "DC"
```
## API
The complete, hopefully self-explanatory, API is:
* `GoogleMapsGeocoder#city`
* `GoogleMapsGeocoder#country_long_name`
* `GoogleMapsGeocoder#country_short_name`
* `GoogleMapsGeocoder#county`
* `GoogleMapsGeocoder#exact_match?`
* `GoogleMapsGeocoder#formatted_address`
* `GoogleMapsGeocoder#formatted_street_address`
* `GoogleMapsGeocoder#lat`
* `GoogleMapsGeocoder#lng`
* `GoogleMapsGeocoder#partial_match?`
* `GoogleMapsGeocoder#postal_code`
* `GoogleMapsGeocoder#state_long_name`
* `GoogleMapsGeocoder#state_short_name`
For compatibility with [Geocoder](https://github.com/alexreisner/geocoder), the following aliases are also available:
* `GoogleMapsGeocoder#address`
* `GoogleMapsGeocoder#coordinates`
* `GoogleMapsGeocoder#country`
* `GoogleMapsGeocoder#country_code`
* `GoogleMapsGeocoder#latitude`
* `GoogleMapsGeocoder#longitude`
* `GoogleMapsGeocoder#state`
* `GoogleMapsGeocoder#state_code`
## Documentation
Complete RDoc documentation is available at [RubyDoc.info](https://www.rubydoc.info/gems/google_maps_geocoder).
## [Contributing to GoogleMapsGeocoder](.github/CONTRIBUTING.md)
## Copyright
Copyright © 2011-2024 Roderick Monje. See [LICENSE.txt](LICENSE.txt) for further details.