Last active
July 24, 2024 18:08
-
-
Save mattradford/bb7679a2671b99ada655 to your computer and use it in GitHub Desktop.
ACF Get Directions map link
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
<?php | |
$location = get_field('map_location'); | |
if ( !empty( $location ) ) : | |
$map_url = 'https://www.google.com/maps/dir/?api=1&destination=' . $location['lat'] . ',' . $location['lng']; | |
echo '<a href=". esc_url( $map_url ) . '" rel="nooopener">Get directions</a>'; | |
endif; | |
?> | |
<p>This should produce a link like this:</p> | |
<a href="https://www.google.com/maps/dir/?api=1&destination=51.072159,1.088130">Get directions</a> | |
See <a href="https://developers.google.com/maps/documentation/urls/get-started#directions-action">https://developers.google.com/maps/documentation/urls/get-started#directions-action</a> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To create a link pointing directly to the location in Google Maps