我使用了地理编码的自动完成,但是当我从下拉菜单中选择时,它给我的地址和长的地址
我需要检查lat和long是否空,然后从发布的地址我必须得到纬度和经度
假设你有lat和long的隐藏值
mapLat& mapLong和输入字段名称是位置
那么你可以检查如下
mapLat& mapLong和输入字段名称是位置
那么你可以检查如下
<html>
<form>
<input type="hidden" name="mapLat">
<input type="hidden" name="mapLong">
<input type="text" name="location">
<input type="submit" name="submit" value="submit">
</form>
</html>
extact($_POST);
if($mapLat =='' && $mapLong ==''){
// Get lat long from google
$latlong = get_lat_long($location); // create a function with the name "get_lat_long" given as below
$map = explode(',',$latlong);
$mapLat = $map[0];
$mapLong = $map[1];
}
// function to get the address
function get_lat_long($address){
$address = str_replace(" ","+",$address);
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$region");
$json = json_decode($json);
$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
return $lat.','.$long;
}