Support

Account

Home Forums ACF PRO Get place name from Google Maps field

Unread

Get place name from Google Maps field

  • Hi,

    I have a Google Maps field in the backend where I can enter an address or a place name, e.g. Allianz Arena, and it will automatically find the full address for it. This makes it easy for publishers adding an address.

    How do I get to display the place name in the frontend?
    With the following code from the ACF Google Maps page I can only get the street details, but not the place name, in my example “Allianz Arena”.

    
    <?php 
    $location = get_field('location');
    if( $location ) {
    
        // Loop over segments and construct HTML.
        $address = '';
        foreach( array('street_number', 'street_name', 'city', 'state', 'post_code', 'country') as $i => $k ) {
            if( isset( $location[ $k ] ) ) {
                $address .= sprintf( '<span class="segment-%s">%s</span>, ', $k, $location[ $k ] );
            }
        }
    
        // Trim trailing comma.
        $address = trim( $address, ', ' );
    
        // Display HTML.
        echo '<p>' . $address . '.</p>';
    }
    

    How could I get that place name?

    Thanks,
    Johannes

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.