Support

Account

Home Forums Front-end Issues Saving Google Map data on front end

Solved

Saving Google Map data on front end

  • I have a form whereby users can update their address details. This saves to an ACF Google Map field. Works fine in WP Admin but whenever this is saved on the front-end the DB isn’t updated. Here’s my code:

            $url = "http://maps.google.com/maps/api/geocode/json?address=". urlencode($member['base_map_location']) ."&sensor=false";
            $response = wp_remote_get($url);
        
            if (!is_wp_error($response) && isset($response['response']['code']) && 200 === $response['response']['code']) {
    
                $body = wp_remote_retrieve_body($response);
                $output = json_decode($body);
                $centre_lat = $output->results[0]->geometry->location->lat;
                $centre_long = $output->results[0]->geometry->location->lng;
                $formatted_address = $output->results[0]->formatted_address;
    
                $member['location_details'] = array('address' => $formatted_address, 'lat' => $centre_lat, 'long' => $centre_long, 'zoom' => 14);
                
            } else {
                
                $errors['base_map_location'] = "There was a problem with your base location postcode";
                
            }
    
        ...
    
            update_field('field_538f370b75f06', $member['location_details'], 'user_' . $current_user->ID);
    
    

    $member[‘location_details’] is formatted fine. Any pointers?

  • Was just a typo!

    `$member[‘location_details’] = array(‘address’ => $formatted_address, ‘lat’ => $centre_lat, ‘lng’ => $centre_long, ‘zoom’ => 14);

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

You must be logged in to reply to this topic.