原來使用了一點點百度地圖的東東
但是感覺想整合但又不想動手
這次又一次使用了高德
在不想整理的過程中,想讓自己做個開始
畢竟有了開始就會有下一次完善
當然,更大的可能會是忘了這回事...
但是有總比沒有強
開始,代碼如下:
<?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日