Support » Plugin: ACF OpenStreetMap Field » How to get attributes in Leaflet/iFrame mode?

  • Resolved parakeet

    (@parakeet)


    How can you access the array attributes of a saved field if the return format is Leaflet or iFrame?

    Vice versa, how can you build a map from the attributes if you output them using Raw format?

    Option 1 is preferable.

    Array
    (
        [lat] => 43.7480482
        [lng] => 7.4387874
        [zoom] => 14
        [address] => Monte-Carlo Bay Hotel & Resort, Avenue Princesse Grace, Monaco-Ville, France
        [markers] => Array
            (
                [0] => Array
                    (
                        [label] => Monte-Carlo Bay Hotel & Resort, Avenue Princesse Grace, Monaco-Ville, France
                        [default_label] => 
                        [lat] => 43.7480482
                        [lng] => 7.4387874
                    )
    
            )
    
        [layers] => Array
            (
                [0] => Wikimedia
            )
    
        [center_lat] => 43.7480482
        [center_lng] => 7.4387874
    )
Viewing 1 replies (of 1 total)
  • Here is the answer…

    If, when in Leaflet or iFrame mode for Return, the recommended…

    the_field('venue', $term_id_prefixed);

    … returns the nice actual map mark-up, then we need to need to secondarily get the object in to a variable in a way that overrides the return format…

    $myvenue = get_field('venue', $term_id_prefixed, false);

    Passing the third parameter as ‘false’ is ACF’s recommended way of doing so. Per the docs: “In this example, the field “image” is an image field which would normally return an Image object. However, by passing false as a 3rd parameter to the get_field function, the value is never formatted and returned as is from the Database.”

    Thus…

    echo $myvenue['address'];

    … properly plucks out my address, even from a Leaflet return.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.