GeoContrast Demo page
GeoContrast allows you to transform a simple text field in a Google Maps Autocomplete search field, bringing the name of streets, cities or an establishments.
Installation
Install it yourself as:
$ gem install geo_contrast
Or add this line to your application's Gemfile:
gem 'geo_contrast'
And then execute:
$ bundle
Usage
In application.js
insert the following line:
//= require geo_contrast
Inside application.html.erb
call the Google Places Autocomplete:
<%= javascript_include_tag 'application', '//maps.googleapis.com/maps/api/js?libraries=places','data-turbolinks-track' => true %>
Then, inside your form just add a class (or id) to your input field and inside application.js
call the GeoContrast
initialize function:
$('.your_class').geoContrast();
Customizing the results
You have a few options to customize the return address from Google. You can specify the kind of search with this options:
Format
With this it returns the short address. Eg. "San Francisco":
$('.your_class').geoContrast({format: "short"});
This one returns the long version of the address. Eg. "San Francisco, California, United States of America":
$('.your_class').geoContrast({format: "formatted"});
Gmaps Options
If you want to search just for cities, for example, you can pass a option to specify this:
$('.your_class').geoContrast({format: "formatted", options_gmaps: {types: ['(cities)']}});
The options are:
- 'geocode' -> For addresses.
- '(regions)' -> For administrative regions.
- 'establishment' -> For businesses.
- '(cities)' -> For just city names.
ROADMAP
Here is the next things that will be (probably) implemented:
- Better way to handle coordinate fields (latitude, longitude)
- Find a way to put Google Maps easily
- Easy integration with SimpleForm
...and more
Contributing
- Fork it ( https://github.com/codelandev/geo-contrast/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request