【发布时间】:2013-12-05 22:42:20
【问题描述】:
我正在使用 php 将纬度和经度转换为 WordPress 自定义字段中的地址。除了地址末尾的国家(例如 1234 1st City State 90210 USA)之外,它按我想要的方式工作。
这是我用来进行转换的代码。关于如何删除国家名称的任何想法?
function getaddress($post_id)
{
$coorloc = get_field('event_location');
$url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.urlencode($coorloc).'&sensor=false';
$json = @file_get_contents($url);
$data=json_decode($json);
$status = $data->status;
if($status=="OK")
$address = $data->results[0]->formatted_address;
update_post_meta($post_id, "geocoderaddress", $address);
}
add_action('acf/save_post', 'getaddress', 1);
【问题讨论】:
标签: javascript php wordpress google-maps