Injecting Geolocate Lat and Long from address into custom post field

So far, all I’ve managed to do is replace the hidden custom post field with the text I want.

I’m using Geolocation plugin, but all that does is stick latlong in the entires page.

Found this, but it doesn’t seem so work (I know this isn’t a proper solution to the issue, but I thought if I could atleast get the lat/long into fields I could wangle the rest.

add_action( 'gform_pre_submission_7', 'mr_get_longlat_of_address' );
function mr_get_longlat_of_address( $form ){
	$address = sanitize_text_field( $_POST['input_2.1'] ' '.$_POST['input_2.3'] );
	$address .= ', Kansas, United States';
	$coordinates = file_get_contents( '' . urlencode($address) . '&sensor=true' );
	if( $coordinates ) {
		$coordinates		= json_decode($coordinates);
		$_POST['input_3']	= $coordinates->results[0]->geometry->location->lng;
		$_POST['input_4']	= $coordinates->results[0]->geometry->location->lat;

I know I’m asking a big favour, but I’m at a total loss. I do content writing and design stuff. I’m a PHP amateur, but I know this can be done in relatively short piece of code… but I’m going nuts trying to figure this out :frowning:

Thanks so much for any help in advance!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.