簡單使用高德地圖開放平台API


需求說明

輸入經緯度,得到城市名

挑選API

使用高德逆地理編碼API,點擊查看文檔

demo

<?php
      /**
     * 根據輸入的經緯度返回城市名稱
     * @param $longitude 終點坐標(經度)
     * @param $dimension 終點坐標(緯度)
     * @return string
     */
    public function getCity($longitude,$dimension)
    {
        $location = $longitude . ',' . $dimension;//坐標
        $key = '6b3*************************6995';//高德地圖key-web
        $curl = 'https://restapi.amap.com/v3/geocode/regeo?output=json&location=' . $location . '&key=' . $key . '&radius=1000&extensions=base';
        $content = file_get_contents($curl);
        $result = json_decode($content, true);
        if ($result['status'] == 0) {
            return '接口請求錯誤,請檢查參數是否正確';
        } else {
            $city = $result['regeocode']['addressComponent']['city'];
            return $city;
        }
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM