Skip Navigation

[Resolved] Latitude & Longitude Fields

This support ticket is created 5 years, 1 month 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.

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 9 replies, has 2 voices.

Last updated by Shane 5 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1357891

I have this same question (https://toolset.com/forums/topic/latitude-longitude-fields/)

A Support member has suggested using save_post hook to store the lat/lon coordinates.

But I couldn't any way to Latitude & Longitude. It is on text field (name attribute) called "toolset-extended-form-wpcf[test-google-map-address-01][latitude]" & "toolset-extended-form-wpcf[test-google-map-address-01][longitude]"

But I don't know how to access it from inside save_post or whatever suitable hook. Could you help me?

#1358131

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Afriel,

I'm a bit unsure what you want to achieve.

Is it that you want to be able to store the longitude and latitude in a field ?

Please let me know.
Thanks,
Shane

#1358413

Yes, I want to store the longitude and latitude in two custom field in the database.

#1359019

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Afriel,

The best thing you can do is to create 2 single line fields, one for Longitude and one for Latitude.

You can also use these fields to populate the map as well if you choose to do so.

Thanks,
Shane

#1359367

Sorry Shane, I didn't understand, You mean create 2 fields and manually add Latitude & Longitude? I am just looking way to save Latitude & Longitude in the database when publish/update the post. Currently, toolset saved only the location address/

#1359761

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Afriel,

The Latitude & Longitude values are being stored in the database but not as post meta. They will need to be retrieved from the wp_options table which would require a manual query.

The better option is to store your Latitude & Longitude as separate custom meta from the address itself so you can retrieve the values like regular custom fields.

"You mean create 2 fields and manually add Latitude & Longitude?"

Essentially yes thats what i'm saying.

Thanks,
Shane

#1361055

---------------------
"You mean create 2 fields and manually add Latitude & Longitude?"

Essentially yes thats what i'm saying.
---------------------

Is there any way to make automatic it? It is little time-consuming work to manually copy/paste Latitude & Longitude each time when updating post.

#1361335

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2019-10-14 at 8.31.15 AM.png

Hi Afriel,

It is possible to do it with JS manipulation, however is it that you want the values to be stored in separate fields?

Reason is because we can get the value of the data-coordinates attribute from the address. We will get the value as you see it in my screenshot.

Would you want them to be separated and then added to the longitude and latitude field ?

Please let me know.
Thanks,
Shane

#1361761

Thanks Shane. I created two toolset custom fields called "wpcf-latitude" and "wpcf-longitude". I am trying to store those values on "wpcf-latitude" and "wpcf-longitude". Could you give a help to store them? Any sample code or link is much appreciated.

#1362093

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Afriel,

Ok so I came up with a solution for this using Javascript.

You will need to install the plugin plugin here
https://wordpress.org/plugins/custom-css-js/

Then add a new JS custom js and set the "Where in site" option to "In Admin". Finally add the following to the editor and save it.

jQuery(".editor-post-publish-button").click(function() {
  var cords = jQuery("input[name='wpcf[address]']").attr("data-coordinates");
  var splitcords = cords.split(',');
  jQuery("input[name='wpcf[latitude]']").val(splitcords[0].replace("{",""));
    jQuery("input[name='wpcf[longitude]']").val(splitcords[1].replace("}",""));

});

Note you will need to replace "wpcf[address]" with the appropriate value. Lets say your field is called "Location" then the slug will be "wpcf-location". To add this to the code it will become "wpcf[location]"

I bind the code to the update button on the post, so it will fire when the button is clicked.

Please let me know if this helps.
Thanks,
Shane