Last active
September 22, 2016 10:04
-
-
Save johanneslamers/7fcb14759ed7c0a9aa9b to your computer and use it in GitHub Desktop.
Craft CMS automatic distance calculator between site visitor and entry author
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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