zoukankan      html  css  js  c++  java
  • 高德地图接口使用整理

    原来使用了一点点百度地图的东东

    但是感觉想整合但又不想动手

    这次又一次使用了高德

    在不想整理的过程中,想让自己做个开始

    毕竟有了开始就会有下一次完善

    当然,更大的可能会是忘了这回事...

    但是有总比没有强

    开始,代码如下:

    <?php 
    /**
     * 高德地图初步封装使用
     */
    class Amap 
    {
        private $web_key = "";
    
        public function __construct($web_key) 
        {
            $this->web_key = $web_key;
        }
    
        #简单操作
        /**
         * 逆地理编码
         * @param  [type] $location 经纬度拼接地址
         * @return [type]           [description]
         * 接口地址:https://restapi.amap.com/v3/geocode/regeo?parameters
         //* 正地理编码接口地址:https://restapi.amap.com/v3/geocode/geo?parameter#
         * 请求方式:GET
         * 高德示例:https://restapi.amap.com/v3/geocode/regeo?output=json&location=116.310003,39.991957&key=<用户的key>&radius=1000&extensions=all
         */
        public function getregeo($location)
        {
            $getUrl = 'https://restapi.amap.com/v3/geocode/regeo?output=json&location='.$location.'&key='.$this->web_key;
            $datas = json_decode(file_get_contents($getUrl),true);
    
            #只获取对应城市地址
            return $datas['regeocode']['addressComponent']['province'];
            // pre($datas);
        }
    
        /**
         * 距离测量
         * @param  [type] $origins     目标位置坐标
         * @param  [type] $destination 当前位置坐标
         * @return [type]              [description]
         * 接口地址:https://restapi.amap.com/v3/distance?parameters
         * 请求方式:GET
         * 高德示例:https://restapi.amap.com/v3/distance?origins=116.481028,39.989643|114.481028,39.989643|115.481028,39.989643&destination=114.465302,40.004717&output=xml&key=<用户的key>
         */
        public function getdistance($origins,$destination)
        {
            $getUrl = 'https://restapi.amap.com/v3/distance?origins='.$origins.'&destination='.$destination.'&output=json&key='.$this->web_key;
            $datas = json_decode(file_get_contents($getUrl),true);
            // pre($datas);
            return $datas;
        }
    
        
    }
    
    
    
    ?>

    以上是本次使用的两方法

    总算是有个开头了

    慢慢完善吧...

    双向的奔赴才有意义

    一个人再怎么坚持也会有累的时候

    2020年08月28日

  • 相关阅读:
    Unity 3D 一个简单的角色控制脚本
    Unity3D 纹理偏移(TextureOffset)浅析
    递归函数的原理
    彻底搞定 C/C++ 指针
    zygote的分裂
    SystemServer分析
    Zygote原理学习
    Vmware Linux虚拟机磁盘扩容方法
    Ubuntu12.04 64bit版本下载Android源码完整教程
    Android2.2源码属性服务分析
  • 原文地址:https://www.cnblogs.com/YFYQ/p/13578798.html
Copyright © 2011-2022 走看看