To create a simple, dynamic link that opens directions in Google maps, you can use a simple link URL that includes, at a minimum, a destination
. Most commonly, you'll use attribute variable from your data to create this destination.
Let's assume we have 3 fields in our data that make up an address: street, city, country. The following URL can be used in custom popup editor using attribute field name placeholders, wrapped in curly brackets.
https://www.google.com/maps/dir/?api=1&destination={street}+{city}+{country}
Where only a single field contains a complete address, use only that field:
https://www.google.com/maps/dir/?api=1&destination={full_address}
If your attribute data includes coordinates, you could use the coordinate pair, separated by a comma:
https://www.google.com/maps/dir/?api=1&destination={lat},{lon}
Inserting your URL into a link in custom popup editor will generate a dynamic link for each feature that populates the attribute field placeholder with the information from the selected feature. The link will open either as a new browser tab on a desktop PC, or the Google Maps app on a mobile device.
If you only specify a destination
, the route will originate from your current location, as detected by the web browser or your device. Location services must be enabled on the device and/or permissions for the web browser to access device location are required for this to work.
Optional parameters
By specifying optional parameters, the origin, method of transport or waypoints can be set.
Origin
If you would like directions to originate at a specific location, use the origin
parameter. origin
can be a fixed address, a coordinate pair, or attribute placeholders from your data.
For example, you have a warehouse
field in your data that is the full address of the warehouse for a given distribution territory. The directions link can include that parameter so the route will from warehouse
to full_address
will be planned:
https://www.google.com/maps/dir/?api=1&destination={full_address}&origin={warehouse}
Either the origin
or the destination
could be a fixed address.
https://www.google.com/maps/dir/?api=1&destination={full_address}&origin=114 Main St, Houston, TX 77002, United States
https://www.google.com/maps/dir/?api=1&114 Main St, Houston, TX 77002, United States&origin={warehouse}
Mode of travel
travelmode
as the name suggests, sets the method of transport. Available values are driving
, walking
, bicycling
, and transit
https://www.google.com/maps/dir/?api=1&destination={full_address}&travelmode=driving
Waypoints
waypoints
are one or more stops along the route to the destination
. If multiple waypoints
are specified, include a pipe separator |
between each.
https://www.google.com/maps/dir/?api=1&destination={full_address}&waypoints={address_2}|{address_3}
When using multiple URL parameters, make sure you use an ampersand "&" between each parameter.
eg.&destination={address}&travelmode=bicycling
Google's service should be used in accordance with Google's privacy policy and terms. Mango does not warrant that locations in your data will exist in Google's maps index, nor that a valid route to your desired destination or waypoints exists, nor that your desired transport mode is available. For more information on routing URLs, please see Google's documentation.