Skip Navigation

[Resolved] Get latitude longitude value from "Address field"

This support ticket is created 6 years 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by Nigel 6 years ago.

Assisted by: Nigel.

Author
Posts
#1140180

In toolset type
We have "Address field" that contain both the Address value and Coordinates(latitude, longitude) Value

I need to use latitude longitude value in order to "EXPORT" it to another site.
Could you please guide me to get the latitude longitude value.

Thank you

#1140339

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

The coordinates are stored in a cache in the wp_options table, they are not stored as postmeta (which the address itself is), so are not amenable to being exported alongside the posts themselves.

If you look in the wp_options table you will find the cache stored as an array with the option name "toolset_maps_address_coordinates".

#1140937

Hi, Nigel
Thank you for the clear answer.

May I ask more about the sake of export.Is it possible
If i make the custom field called "Lat" and "Long"
Then make it auto input by the number from "Address field" Coordinate

#1141364

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

What software are you using to export your data?

I think your best option is to use the WP All Export plugin (hidden link).

The great thing about this plugin is that for each record that you export you can pass the value through a custom function.

So you could export the address field 3 times.

The first time you export it as-is, to show the text address.

The second time you pass the address through a function which returns the latitude (which you look up from the cache stored in wp_options).

The third time you pass the address through a function which returns the longitude (which you look up from the cache stored in wp_options).

#1141611

Do You have any suggestion of how to do it ?

#1142288

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I haven't tried to export the data using WP All Export, but I know you can pass the values to be exported through a function.

You can use these functions to get the lat and to get the lon for an address which you pass to them (the address will come from the address field you are exporting):

function tssupp_get_lat( $address ){
	
	$cache = get_option( 'toolset_maps_address_coordinates' );
	$lats = wp_list_pluck( $cache, 'lat', 'address_passed' );

	$lat = $lats[ $address ];

	return $lat;
}


function tssupp_get_lon( $address ){
	
	$cache = get_option( 'toolset_maps_address_coordinates' );
	$lons = wp_list_pluck( $cache, 'lon', 'address_passed' );

	$lon = $lons[ $address ];

	return $lon;
}
#1142467

It's not working

I have the example of the function that work before. I'm not so good with php, maybe you can figured out how it should work work.

This function I use to get the Province or District name which is the parent of the listing.

function get_place_title($relationship_slug){
// Get the ID of the parent post, which belongs to the "place" post type
$place_id = toolset_get_related_post( get_the_ID(), $relationship_slug, 'parent' );
// Get all the parent (place) post data
$place_post = get_post( $place_id );
 
// Get the title of the parent (place) post
$place_name = $place_post->post_name;
// Get the contents of the parent (place post
$place_content = $place_post->post_content;

	return "$place_name";
}

And I sent this line

[get_place_title("province-listing")]

as the function call

#1143001

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, I don't understand.

Your question was how to export addresses with the latitude and longitude, but the code sample you provided in the last reply seems to be related to something completely different.

Could you please clarify what it is you are trying to do?