[themify_is_logged_in]
[php]
function update_GEOmyWP( $post_id, $form_id ) {
// check the right FORM
if ( $form_id != 194 ) {
return;
}
// make sure post ID exists.
if ( ! $post_id ) {
return;
}
if ( isset( $_POST[‚google_map‘] ) ) { // Aufnahmeort ist der Key des Feldes
//$returnValue = unserialize( $_POST[‚google_map‘] );
list( $rs_address, $rs_lat, $rs_lng ) = explode( ‚||‘, $_POST[‚google_map‘] );
list( $rs_street, $rs_place, $rs_country ) = explode( ‚,‘, $rs_address );
list( $rs_postcode, $rs_city ) = explode( ‚ ‚, trim( $rs_place ), 2 );
$lat_lng = (float)$rs_lat .‘,‘.(float)$rs_lng;
if ( $rs_address ) {
update_post_meta( $post_id, ‚_citadela_address‘, trim( $rs_address ) );
}
if ( $rs_lat ) {
update_post_meta( $post_id, ‚_citadela_latitude‘, (float)$rs_lat );
}
if ( $rs_lng ) {
update_post_meta( $post_id, ‚_citadela_longitude‘, (float)$rs_lng );
}
if ( $rs_lat && $rs_lng ) {
update_post_meta( $post_id, ‚_rockspot_latitude_longitude‘, (float)$rs_lat .‘,‘.(float)$rs_lng );
update_post_meta( $post_id, ‚_rockspot_bundesland‘, getProvince($lat_lng));
}
if ( $rs_street ) {
update_post_meta( $post_id, ‚_rockspot_street‘, trim($rs_street) );
}
if ( $rs_city ) {
update_post_meta( $post_id, ‚_rockspot_city‘, trim( $rs_city ) );
}
if ( $rs_place ) {
update_post_meta( $post_id, ‚_rockspot_postcode_city‘, trim( $rs_place ) );
}
if ( $rs_postcode ) {
update_post_meta( $post_id, ‚_rockspot_postcode‘, trim( $rs_postcode ) );
}
if ( $rs_country ) {
update_post_meta( $post_id, ‚_rockspot_country‘, trim( $rs_country ) );
}
}
}
add_action( ‚wpuf_add_post_after_insert‘, ‚update_GEOmyWP‘, 10, 2 );
add_action( ‚wpuf_edit_post_after_update‘, ‚update_GEOmyWP‘, 10, 2 );
function getProvince ($lat_lng){
$url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=".$lat_lng."&key=AIzaSyA701XV1EOlkeSDgmjxV7fRRQ-QDKx2mfA";
$data = @file_get_contents($url);
$jsondata = json_decode($data, true);
$jsondata = array_reverse($jsondata[results][0][address_components]); // to get administrative_area_level_1
return $jsondata[2][long_name];
}
[/php]
[/themify_is_logged_in]