mcguffin / acf-openstreetmap-field

WordPress ACF Field for OpenStreetMap
https://wordpress.org/plugins/acf-openstreetmap-field/
GNU General Public License v3.0
107 stars 21 forks source link

Add Marker in Text-Form #22

Closed vozer closed 4 years ago

vozer commented 4 years ago

Thanks for the addon so far!

I am wondering if there is a Possibility to also generate the html output instead of a map as a Link to Open-Street-Maps like:

<a href"link to open street map">British Museum, Russell Street, London

or the have both at the same time?

mcguffin commented 4 years ago

Hi, you can achieve this usng the raw data return format. The PHP-Code printing the link should look like this somehow:

$value = get_field('map_field_key');
if ( count( $value['markers'] ) ) {
    printf('<a href="https://www.openstreetmap.org/#%d/%f/%f">%s</a>', 
        $value['zoom'],
        $value['markers'][0]['lat'],
        $value['markers'][0]['lng'],
        esc_html( $value['markers'][0]['label'] )
    );
}
// Responsible pasting: Please comprehend before you paste!
vozer commented 4 years ago

Thx a lot! Works like a charm! i just changed the link to also show the marker:

<?php $value = get_field('ubicacion_real'); if ( count( $value['markers'] ) ) { printf('<a href="https://www.openstreetmap.org/?mlat=%f&mlon=%f#map=%d/">%s</a>', $value['markers'][0]['lat'], $value['markers'][0]['lng'], $value['zoom'], esc_html( $value['markers'][0]['label'] ) ); } ?>