I am trying to access the lat and log that google maps encodes from a full address.
I expected to find in the the user-address field (which is an address type)
See this code
------------
$start_post_ID = $_SESSION["startpostid"]; //first pilot post ID
$start_latlon = explode(",", get_post_meta($start_post_ID, 'wpcf-user-address', true));
$this_latlon = explode(",", get_post_meta($post_ID, 'wpcf-user-address', true));
$a = intval(distance($start_latlon[0], $start_latlon[1], $this_latlon[0], $this_latlon[1], "M"));
update_post_meta( $post_ID, 'wpcf-range', $a );
--------------
Can you please advise what is the proper parameter name to use and how to access it here
See the image, that the address has been properly encoded into lat and lon
Hi,
Thank you for contacting us and I'd be happy to assist.
Toolset Maps stores the selected human-readable address and not the lat and lon coordinates as the raw custom field values in the address type fields. For this reason, "get_post_meta" function won't help in this case.
To get the lat and lon coordinates from the address type custom field, you can use the "types_render_field" function from Types Fields API.
( ref: https://toolset.com/documentation/customizing-sites-using-php/functions/#address )
Example:
// get lat from a custom field "user-address" from post with ID 1
$user_lat = types_render_field('user-address', array('item' => '1', 'format' => 'FIELD_LATITUDE'));
// get lon from a custom field "user-address" from post with ID 1
$user_lat = types_render_field('user-address', array('item' => '1', 'format' => 'FIELD_LONGITUDE'));
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar