OpenPlaces is a Location Autocomplete Rails 4 Engine. It imports NaturalEarthData.com and Geonames.org geospatial data and provides a mountable JSON/GeoJSON API endpoint.
OpenPlaces uses Postgres and the PostGIS adapter to do fast geo-spatial and full text search. A Rails 4 application with a Postgres database with the PostGIS extension is required to use OpenPlaces.
- Add 'open_places' to your Gemfile and bundle install
- Run
rake open_places:install:migrations
- Run
rake db:migrate
- Mount the engine: mount OpenPlaces::Engine => "/api/geo"
- Restart your server
Visit: http://localhost:3000/api/geo?q=Seattle
The api endpoint is able to do a couple different operational queries
- q= Exact Match
- like= Fuzzy Match (using postgres ts_vector)
- contains= Contains (LIKE '%?%')
- starts= Starts with (LIKE '?%')
- ends= Ends with (LIKE '%?')
Additionally, it will take a near param, a latitude,longitude string. With a near param, a distance attribute is added and the results are ordered by population, distance, and ts_rank if the operational query is like.
OpenPlaces includes a rake task to build a single database table of normalized data. For convenience, a 12Mb CSV file is included for fast import. The data includes the following fields:
- geo_type
- subtype
- scalerank
- code
- name
- long_name
- country
- country_code
- province
- province_code
- continent
- region_un
- subregion
- region_wb
- latitude
- longitude
- x_min
- y_min
- x_max
- area
OpenPlaces imports Countries, States/Provinces, Cities, National Parks, Lakes and Rivers from Natural EarthData.com and Geonames.org.
- 255 Countries
- 4516 States/Provinces
- 146474 Places (Metros/Cities/Towns)
- 61 US National Parks
- 743 Lakes
- 1454 Rivers