[Resolved] Extracting Longitude, Latitude from Maps Field
This thread is resolved. Here is a description of the problem and solution.
Problem:
The customer was using the "save_post" hook to automatically fill lat/lon coordinates from a Toolset address type field into another custom field, but the values were not becoming available for new posts.
Building a directory site and want to be able to sort results by proximity. In order to do this the location needs to be stored as longitude, latitude. Google Maps already has this info but I'm not sure how to get it and insert into the field. It's in a different array from the rest of the address data. hidden link
Is there any documentation that you are following?
I managed to get this working for front end edit form by adapting the code from extracting the state to taxonomy.
This works on edit but not create. Perhaps because I used a shortcode to get lat/long and that value is not yet available on first save. Not sure how else to get the lat/long as that data is in a different array from the address components. I'm sure there is a better way.
Your understanding is correct and the use of shortcode to get the custom field value from the table, it too early for new posts, as the value has not been saved in the table yet.
Instead of getting the values from the custom fields table, you can use the superglobal "$_POST".