web服务API 地址转码
function getGeoCoding($address)
{
$url = "https://api.map.baidu.com/geocoding/v3/?address=" . $address . "&output=json&ak=F552bedbee2ec8fa6bae7b7a08201cbd&callback=showLocation";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
echo getGeoCoding("***558号");
javascript服务API 地址转码
function transAddress() {
var address = $("#address").val();
//获取经纬度;
getPoints(address);
}
function getPoints(address) {
var map = new BMap.Map('container');
map.centerAndZoom(new BMap.Point(116.331398, 39.897445), 12);
var myGeo = new BMap.Geocoder();
myGeo.getPoint(address, function (point) {
$("#lnglat").val(point.lng + "," + point.lat);
}, '')
}
Done!