Skip Navigation

[Cerrado] lat/long Coordinates

This support ticket is created hace 9 años, 2 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 respuestas, has 3 mensajes.

Last updated by Waqas hace 9 años, 2 meses.

Assisted by: Waqas.

Autor
Mensajes
#246421

How can I automatically generate lat/long coordinates from a custom field? I need it for my website. I'm using CRED so the people can add projects and add an address. I would like to display the project on the google map but I can't ask the users to search for lat/long coordinates.

Maybe 5 years ago it would work, but now everything is automated , responsive and modern with nice user experience. I have to find some solution, otherwise the lack of this feature will ruin my project 🙁

Kind regards,
Michael

#246627

Hi Michael,

It is possible not possible with toolset, but you can try Google map API to automatically generate lat/long coordinates from a custom field.
For example, you are using custom field "address" to store a string of address, like "USA, xx city, xxx street, #123", then you can use google API to get its lat/long coordinates.
With wordpress action "save_post", add codes in your theme/functions.php:

//* Function to retrieve & store latitude and longitude of an address field using Google Maps api
function geocode_address($post_id)
{
    $custom_fields = get_post_meta($post_id, 'wpcf-address', true);
    if(!empty($custom_fields))
    {
        $resp = wp_remote_get( "<em><u>hidden link</u></em>".urlencode($custom_fields["wpcf-map-marker-address"][0])."&sensor=false" );
        if ( 200 == $resp['response']['code'] ) {
            $body = $resp['body'];
            $data = json_decode($body);
            if($data->status=="OK"){
                $latitude = $data->results[0]->geometry->location->lat;
                $longitude = $data->results[0]->geometry->location->lng;
                update_post_meta($post_id, "wpcf-latitude", $latitude);
                update_post_meta($post_id, "wpcf-longitude", $longitude);
            }
        }
    }
}
add_action('save_post', 'geocode_address');

More help:
Maps API - Google Developers
hidden link

#247810

Hi Luoy,
thank you for your help, is it possible to create a new field that will be generated from few another fields, I mean an address field that will be created from following fields:
- country
- city
- street
- postal code

I understand I would need to create an additional hidden address field and then pass the values from above 4 fields?

#249179

Waqas
Supporter

Languages: Inglés (English )

Timezone: Asia/Karachi (GMT+05:00)

You can create custom fields on-fly by using Word Press API. Please see http://codex.wordpress.org/Function_Reference/add_post_meta for a reference.

However, you might want to create such fields when your CRED form is posted. For this you may look into CRED API at https://toolset.com/documentation/user-guides/cred-api/. Here you can find several actions to hook up with required event.

Please let me know if I can help you with anything related.

El debate ‘[Cerrado] lat/long Coordinates’ está cerrado y no admite más respuestas.