高德地址常用接口实例

2019-01-16 14:53:51   PHP

  定位  

调用高德的浏览器定位获取经纬度

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>浏览器精确定位</title>
<body>
<script src='/js/jquery-1.8.3.js'></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.10&key=xxxxxxxx"></script>
<script type="text/javascript">
$(function(){
    AMap.plugin('AMap.Geolocation', function() {
        var geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位,默认:true
            timeout: 10000,          //超过10秒后停止定位,默认:5s
            buttonPosition:'RB',    //定位按钮的停靠位置
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
            zoomToAccuracy: true,   //定位成功后是否自动调整地图视野到定位点
        });
        geolocation.getCurrentPosition(function(status,result){
            if(status=='complete'){
                onComplete(result)
            }else{
                onError(result)
            }
        });
    });

    //解析定位结果
    function onComplete(data) {
        var lng = data.position.lng;
        var lat = data.position.lat;
        var postion = lng+','+lat;//获取实时经纬度
    }
    //解析定位错误信息
    function onError(data) {
       //调用失败
       alert(data.message);
    }
})
</script>
</body>
</html>

调用高德地区编码接口获取地理信息

class Geo
{
    /**
     * @param $address 详细地址
     * 
     */
    public function  index($address)
    {
        $origins = '116.481028,39.989643';//初始经纬度
        $curl = new Curl();
        $url = "https://restapi.amap.com/v3/geocode/geo?address=".$address."&output=json&key=xxxxxxxx";
        $res = $curl->Curl($url);
        return $res;

    }
} 

调用高德距离测算接口获取两点之间的距离

class Distance
{
     /**
     * @param $destination 定位坐标
     * 
     */
    public function  index($destination)
    {
                $destination = 121.225431,31.056054;//初始经纬度
        $origins = '121.324130,31.239150|121.246436,31.060513';//目标经纬度
        $curl = new Curl();
        $url = "https://restapi.amap.com/v3/distance?origins=".$origins."&destination=".$destination."&output=json&key=xxxxxxx";
        $res = $curl->Curl($url);
        return $res;

    }
} 

调用高德地区逆编码接口获取指定地点的经纬度

class Regeo
{
    /**
     * @param $location 定位坐标
     * 
     */
    public function  index($location)
    {
        $curl = new Curl();
        $url = "https://restapi.amap.com/v3/geocode/regeo?output=json&location=".$location."&key=xxxxxx&radius=1000&extensions=all";
        $res = $curl->Curl($url);
        return $res;

    }
}