Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jiren/open_location_code
Open Location Codes are a way of encoding location into a form that is easier to use than latitude and longitude. Ref: https://github.com/google/open-location-code
https://github.com/jiren/open_location_code
Last synced: 8 days ago
JSON representation
Open Location Codes are a way of encoding location into a form that is easier to use than latitude and longitude. Ref: https://github.com/google/open-location-code
- Host: GitHub
- URL: https://github.com/jiren/open_location_code
- Owner: jiren
- License: mit
- Created: 2015-05-28T14:39:41.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-02T09:47:25.000Z (over 9 years ago)
- Last Synced: 2024-04-24T22:42:51.575Z (8 months ago)
- Language: Ruby
- Size: 148 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# OpenLocationCode
Open Location Codes are a way of encoding location into a form that is
easier to use than latitude and longitude.Ref: https://github.com/google/open-location-code
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'open_location_code'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install open_location_code
## Usage
```ruby
code = OpenLocationCode.encode(47.365590, 8.524997) # 8FVC9G8F+6X
code = OpenLocationCode.encode(47.365590, 8.524997, 12) #8FVC9G8F+6XQH
code_area = OpenLocationCode.decode('8FVC9G8F+6XQH')
#
```## Rails
Include `Olc` module and call `has_olc` method
`has_olc` has default options `{ field: 'open_location_code', latitude: 'latitude', longitude: 'longitude', code_length: 10 }`
- ActiveRecord
Generate migration to add latitude, longitude and open_location_code fields.
```
rails g migration add_olc_fields_to_events latitude:float longitude:float open_location_code:string
```In Model:
```ruby
class Event << ActiveRecord::Base
include Olchas_olc
# If fields not same as default options
has_olc(field: 'olc', latitude: 'lat', longitude: 'lng', code_length: 10)
end
```- Mongoid
`has_olc` will define field based on passed options[:field] value.
```ruby
class Event
include Mongoid::Document
include Olc
field :latitude, type: Float
field :longitude, type: Floathas_olc
end
```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
1. Fork it ( https://github.com/jiren/open_location_code )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request