Home Forums Feature Requests ACF Map store city in database


ACF Map store city in database

  • Hello!

    I am using the map field in a front-end posting, where users can add auto listing.

    They are required to choose an address by placing a pin on the map, or typing the adress.

    I managed to get the map to show up in single listing, and by using the bellow code, i can echo the city name as text :

    function location_shortcode( $atts ) {

    extract( shortcode_atts(
    ‘id’ => ”,
    ), $atts )

    if ( isset( $id ) && get_field(‘loc_de_intalnire’, $id) ) {

    $google_map = get_field(‘loc_de_intalnire’, $id);

    $url = ‘’.$google_map[‘lat’].’,’.$google_map[‘lng’].’&sensor=true’;
    $data = @file_get_contents($url);
    $jsondata = json_decode($data,true);
    if(is_array($jsondata) && $jsondata[‘status’] == “OK”)

    // city
    foreach ($jsondata[“results”] as $result) {
    foreach ($result[“address_components”] as $address) {
    if (in_array(“locality”, $address[“types”])) {
    $city = $address[“long_name”];


    $location = $city;

    return $location;

    add_shortcode( ‘location’, ‘location_shortcode’ );

    I would like to make a search form, where users can search for the city,like this:

    <option value=\”” . $city . “\”>” . $city . “</option>

    Can anyone help me achieve that?

    Thank you for trying!

  • Hi @viorelepuran,

    Thanks for the post.

    You can make use of the same logic that you are using to pass the location within the acf/load_field filter to populate the values in a select field.

    The ACF resource pages have a handy tutorial on this here:

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

The topic ‘ACF Map store city in database’ is closed to new replies.