Support

Account

Home Forums ACF PRO Google maps api state field

Solving

Google maps api state field

  • I already posted about this in feature requests but thought I’d try here to see if there was a solution.

    Is there anyway to just get the state field from the Google map?

  • Hi @qwik3r

    Here is some code that you could use to separate the values from the string:

    <?php 
    // vars 
    $contact_address = get_field('business_google_map', 'option'); 
    ?> 
    
    <?php $address = explode( "," , $contact_address['address']); 
    echo $address[0].', '; //street number 
    echo $address[1].', '; //city 
    echo substr($address[2],0,3).substr($address[2],3,6); //state + zip 
    ?>
  • Hey James,

    Thanks for this, however I’m not seeing any outputted results.

    First I should preface that this is in a repeater because I plan on having more than one address associated with a listing. But for this test it shouldn’t matter.

    I created a shortcode to test and it just outputs ” and nothing else.

    Doing a var_dump of the field gets this, not sure if it helps.

    array(1) { [0]=> array(2) { ["dancer_address"]=> array(3) { ["address"]=> string(19) "Miami, Florida, USA" ["lat"]=> string(10) "25.7616798" ["lng"]=> string(18) "-80.19179020000001" } ["state"]=> string(2) "FL" } } , ,

    Disregard the state field that is shown because that is not part of the Google Map itself, it’s a custom field I added to the repeater because I was stumped on how to accurately pick out the state from the Google Map array, so I just created a new field to be added manually.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.