Skip Navigation

[Resolved] We’d like to store the LAT and LONG of the Address field as product meta

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to extract the latitude and longitude from a Toolset Address field and store them as custom fields.

Solution:
This will need custom code. Hooked to the cred_save_data for Toolset forms, or the save_post for the admin screens. You can use the format argument in the types_render_field function or the types shortcode. Read more about it here https://toolset.com/documentation/customizing-sites-using-php/functions/#address

Relevant Documentation:

This support ticket is created 3 years, 8 months ago. 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.

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

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 6 replies, has 2 voices.

Last updated by Jamal 3 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#2055559

Hello,

I think the title says it all: we'd like to use toolset as a replacement to Geo My WP (Toolset Maps), however, the issue is that we saw that the toolset maps plugin does not store lat and long fields in the database. Is this possible somehow? We have a custom developed API which would use these field to display the products on our custom developed map.

#2056015

Hello and thank you for contacting the Toolset support.

Toolset Maps does not store the latitude and longitude in the postmeta table. The latitude and longitude are stored in a Toolset cache table to leverage distance search using MySQL geo features.

Unfortunately, we do not offer a proper API to let you reuse the coordinates. You will need to perform another request to the MAPs API(Google or Azure) and store the latitude-longitude in a custom field.
hidden link

I hope this answers your question. Let me know if you have any questions.

#2056023

Hello.

Thank you for the quick reply. Could you please assist us in this issue a bit further? Is this possible to do without custom development (does Toolset offer such custom fields)?

Another question is - is it possible to integrate this plugin with Geo My WP, for example? The address field could fill out GMWP's address field as well, and that stores the lat/long in the database.

#2056027

Also, just to be clear: Toolset makes the request only when the Address is set for the post type, and not every time a user uses the map, right? Just asking, because we have more than 50k users and it would be really expensive if it did that.

#2056087

Indeed, Toolset queries Google or Azure Maps, only one time. Then it stores the coordinates in the cache table. This ensures that the website does not exceed the rate limit for the Maps API. In fact, Toolset will not perform more than 10 requests per minute.

I am sure, Toolset Maps can be integrated with GMWP. But it will require custom code. There is no integration out of the box.

Toolset stores the clear address as a string in the Address custom field. The coordinates are always stores in the cache table.
You will need to add custom code, hooked to the post's save action, and check if the post has already the coordinates or query the Maps API for it and store it in a custom field.
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
- https://developer.wordpress.org/reference/hooks/save_post/

Please note that custom code is out of the scope of the Toolset support. If you are not familiar with programming, consider hiring a developer. Check the list of our partners here https://toolset.com/contractors/

#2065219

Hello Jamal,

Thank you for your answer, we figured out what we'll do 🙂

Kind regards,

Botond

#2106043

Hello,

I just found out another solution that would not need any calls to MAPS API and I would like to share it here, for you and for other users. My apologies for missing it in the first time.

Well, it will still need custom code. However, this time you won't need to call the Maps APIs because the data is already stored on the Toolset database. You can use the format argument in the types_render_field function or the types shortcode. Read more about it here https://toolset.com/documentation/customizing-sites-using-php/functions/#address

All the best,
Jamal