Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bertrandkeller/jekyll-geocode
Geo-encode addresses from a YAML for drawing maps with Jekyll
https://github.com/bertrandkeller/jekyll-geocode
jekyll jekyll-plugin
Last synced: 2 months ago
JSON representation
Geo-encode addresses from a YAML for drawing maps with Jekyll
- Host: GitHub
- URL: https://github.com/bertrandkeller/jekyll-geocode
- Owner: bertrandkeller
- License: mit
- Created: 2016-10-10T14:16:55.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-20T12:21:20.000Z (about 8 years ago)
- Last Synced: 2024-09-28T18:08:34.527Z (3 months ago)
- Topics: jekyll, jekyll-plugin
- Language: Ruby
- Homepage:
- Size: 32.2 KB
- Stars: 13
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-jekyll-plugins - **Geocode** - geocode](https://rubygems.org/gems/jekyll-geocode)) by Bertrand Keller -- geo-encode addresses from a datafile for drawing maps (Geocoding & Maps)
README
# Jekyll Geocode
Making a interactive maps with adresses is impossible you need the coordinates.
Making a file writing by redactors with directly the coordinates of your data is impossible or too slow.So you need a processus for generating coordinates form addresses by calling a service.
For speed reasons you‘d rather writing the coordinates in files during the build. You will probably generate a JSON file with coordinates in your HTML page displaying map.
I took the [Nominatim](https://nominatim.openstreetmap.org/) open source service from Open Street Map for calling the data.
## Example of YAML : _data/members.yml
```yaml
- name: "Bertrand Keller"
street: "place du vieux marché"
postcode: "76000"
city: "Rouen"
region: "normandy"
country: "france"
- name: "John Doe"
street: "rue Mendès France"
postcode: "76190"
city: "Yvetot"
region: "normandy"
country: "france"
- name: "Samuel Le Bihan"
street: "Place Niemeyer"
city: "Le Havre"
postcode: "76600"
region: "normandy"
country: "france"
```> For key matching, avoid accent in name or create a key in members.yml (ex: geoname) without space and accent.
## Example of configuration _config.yml
```yaml
jekyll_geocode:
file-name: members.yml # Name of the YML store inside _data with a list of datas (required)
file-path: _data # Path of the YML file, folder of your data (_data) by default (optional)
name: name # Name of the field from the YML that will gave the name of the generated file (the name will be downcase and space replace by a dash) (required)
address: address # Name of the address (street + city) or only street field (if city field exists) from the YML (required)
postcode: postcode # Postcode from the YML (optional)
city: city # Name of the town field from the YML, if you have a separated field address and city (optional)
region: region # Name of the region, county or state or all in the same field from the YML (optional)
country: country # Name of the country from the YML (optional)
cache: true # Test if a file already exist
outputfile: place.yml # Give the name of the file for an yml output (otherwise it will be JSON) <= usefull for jekyll-map
```
> The service is very slow (when you have lot of entries) but you can generate files with the cache option. Be carefull, ignore this files in your git tracking files !## Example of loop with JSON : map.html with google map
```liquid
{% for row in site.data.members | sort: 'name' %}
{% assign geoname = row.name | replace: ' ', '-' | downcase %}
var point = new google.maps.LatLng({% for coordinates in site.data.[geoname] %}{{ coordinates.lat }}, {{ coordinates.lon }}{% endfor %});
{% endfor %}
```## Example of loop with YAML : map.html with google map
```liquid
{% for row in site.data.members | sort: 'name' %}
{% assign geoname = row.name | replace: ' ', '-' | downcase %}
{% assign places = site.data.place | where:"title", geoname %}
{% for coordinates in places %}
var point = new google.maps.LatLng({{ coordinates.location.latitude }}, {{ coordinates.location.longitude }});
{% endfor %}
{% endfor %}
```This plugin is used in a production website and working well. You are invited for improvement proposals.