Skip to content

Instantly share code, notes, and snippets.

@johanneslamers
Last active September 22, 2016 10:04
Show Gist options
  • Save johanneslamers/7fcb14759ed7c0a9aa9b to your computer and use it in GitHub Desktop.
Save johanneslamers/7fcb14759ed7c0a9aa9b to your computer and use it in GitHub Desktop.
Craft CMS automatic distance calculator between site visitor and entry author
{% set author = entry.author.city %}
{% set visitor = craft.geo.info.city %}
{% set response = craft.googleMaps.directions({
origin: visitor,
destination: author,
language: 'nl',
avoidFerries: false,
avoidHighways: false,
avoidTolls: false,
optimizeWaypoints: false,
provideRouteAlternatives: false,
travelMode: 'DRIVING',
units: 'km'
}) %}
{% for route in response.routes %}
{% for leg in route.legs %}
approximately {{leg.distance.text}} away from you
{% endfor %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment