Support

Account

Home Forums General Issues Extracting City from Google Map Field

Helping

Extracting City from Google Map Field

  • I have a client on a site that is a few years old and they’ve been using the ACF Google Maps field for their address listings (about 1700 listings). Now they want to have the city as its own field for sorting the listings.

    Is this at all possible, or has it been done any way before?

    I know the ACF Google Map makes the field into an array like:
    Array
    (
    [address] => 3 W 18th St, New York, NY 10011, United States
    [lat] => 40.738917
    [lng] => -73.99243810000002
    )

    but has anyone been able to extract just the city into another field?

    Thanks!

  • Hi @aaronrobb

    While it would be possible to hook into acf/save_post and extract the value from the map field into another field (could be a hidden field if you like) I’m not sure how you would go about making sure you ONLY get the city.. It can be any length of string, with or without spaces etc. etc.

    When I’ve had situations like this in the past I’ve actually used a custom taxonomy for location as well. It can be just for cities but you can also use a hierachial one and let the user apply country > region > city > part (really as far or not as you want).

    The taxonomy makes for much better filtering options as well 🙂

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

The topic ‘Extracting City from Google Map Field’ is closed to new replies.