mcguffin / acf-openstreetmap-field

WordPress ACF Field for OpenStreetMap
https://wordpress.org/plugins/acf-openstreetmap-field/
GNU General Public License v3.0
107 stars 21 forks source link

[feature] add post_meta for Lat & Lng #54

Closed Cyrille37 closed 4 years ago

Cyrille37 commented 4 years ago

Hi, Thanks a lot for that really great plugin.

To make possible searching a post in a bounding box (BBox) we need 2 others post_meta, one for longitude, one for latitude.

What's your opinion ? How do you do for that case ?

Regards.

mcguffin commented 4 years ago

Hi, You're welcome :)

As the field does not only return one lng/lat, it would be quite a hazzle to save the geo coordinates in a separate post meta. Which one should be saved ... the map position? the first marker? the nth marker? How to name the postmeta? What if naming conflicts arise?

You can easily hook into acf/update_value/?type=open_street_map and save your additional post meta there. Something like this should do it (untested):

add_filter('acf/update_value/?type=open_street_map', function( $value, $post_id, $field ) {
    update_post_meta($post_id,'a_very_cool_metakey_lat', $value['lat'] );
    update_post_meta($post_id,'a_very_cool_metakey_lng', $value['lng'] );
    return $value;
}, 10, 3);

@see https://www.advancedcustomfields.com/resources/acf-update_value/

Cyrille37 commented 4 years ago

You can easily hook into acf/update_value/?type=open_street_map and save your additional post meta there.

Yeah! That's the right way, thanks :-)