Home › Forums › Bug Reports › Google Maps field normalization › Reply To: Google Maps field normalization
Just thought I would add too this post.
I had this same issue but did not want to deal with keeping the normalized postmeta fields _latitude and _longitude in sync with the ACF postmeta.
This query “deserializes” the ACF google_maps field so no normalization is required. Obviously it would be better if ACF map field was just normalized by the plugin and not stored as serialized PHP object.
function get_nearest_location_page($latitude, $longitude, $maxdistance = 100) {
global $wpdb;
$location_query = <<<EOF
SELECT wp_posts.post_title as post_title,
wp_posts.ID as post_id,
( 3959 * acos(
cos( radians( %f ) ) *
cos( radians( CONVERT(REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(location.meta_value,';',4),':',-1),'"',''), DECIMAL( 10, 6 )) ) ) *
cos( radians( CONVERT(REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(location.meta_value,';',6),':',-1),'"',''), DECIMAL( 10, 6 )) ) - radians( %f ) ) +
sin( radians( %f ) ) * sin( radians( CONVERT(REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(location.meta_value,';',4),':',-1),'"',''), DECIMAL( 10, 6 )) ) )
) ) AS distance
FROM wp_postmeta as location, wp_posts
WHERE wp_posts.post_type = "page"
AND wp_posts.ID = location.post_id
AND location.meta_key LIKE "service_locations_%%"
HAVING distance < %f
ORDER BY distance ASC
LIMIT 1
EOF;
$location_query_string = $wpdb->prepare($location_query, $latitude, $longitude, $latitude, $maxdistance);
return $wpdb->get_results($location_query_string, ARRAY_A);
}
in this case my field is actually an ACF Pro repeater field named service_locations.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.