Appearance
Distance tag
The distance (and travel time) between two places, without a map. Handy in an entries loop, e.g. "12 min by bike from the station". (from v5.0.0)
The distance by road is calculated by the route provider and cached like a route. With travel_mode="straight" the tag gives the straight line distance, without a route provider or API key.
The tag
As a single tag it gives the distance as text, e.g. 12.3 km:
{exp:reinos_maps:distance address:from="Utrecht Centraal" address:to="Domplein, Utrecht"}WARNING
ExpressionEngine pairs a tag with the first closing tag after it. Don't use the single tag before a tag pair of the same tag in one template, the single tag would become a pair. Use the tag pair everywhere, or close the single tag: {exp:reinos_maps:distance ...}{/exp:reinos_maps:distance} gives the distance as text as well.
As a tag pair it has the variables below:
{exp:reinos_maps:distance address:from="Utrecht Centraal" latlng:to="{location_latlng}" travel_mode="cycling"}
{distance} ({duration:minutes} min by bike)
{/exp:reinos_maps:distance}Tag parameters
address:from
The address to start from.
address:from="" [REQUIRED] if latlng:from is emptylatlng:from
The latitude and longitude to start from.
latlng:from="52.0907,5.1214" [REQUIRED] if address:from is emptyaddress:to
The address to go to.
address:to="" [REQUIRED] if latlng:to is emptylatlng:to
The latitude and longitude to go to.
latlng:to="52.3676,4.9041" [REQUIRED] if address:to is emptytravel_mode
The travel mode, the same values as the route tag, plus straight: the straight line distance, calculated by Maps itself (no route provider, no API key, no duration).
travel_mode="driving" [OPTIONAL]unit
The unit of {distance}: km or mi.
unit="km" [OPTIONAL]lang
The language for the route provider.
lang="en" [OPTIONAL]prefix
A prefix for the variables, e.g. prefix="d:" gives {d:distance}.
prefix="" [OPTIONAL]Tag variables
| Variable | Example |
|---|---|
{distance} | 12.3 km (or 7.6 mi with unit="mi", 850 m below 1 km) |
{distance:meters} | 12345 |
{distance:km} | 12.3 |
{distance:mi} | 7.7 |
{duration} | 1 h 5 min (empty with travel_mode="straight") |
{duration:seconds} | 3900 |
{duration:minutes} | 65 |
When there is no route (or an address is not found), the tag gives {if no_results}, the reason is in the Maps log.
Example
The distance from the visitor's city to every store, straight line, sorted in your own template:
{exp:channel:entries channel="stores"}
<h3>{title}</h3>
{exp:reinos_maps:distance address:from="Amersfoort" latlng:to="{store_latlng}" travel_mode="straight"}
{distance} as the crow flies
{/exp:reinos_maps:distance}
{/exp:channel:entries}