12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Utils;
- class GaodeMaps
- {
- const AK = '5bc6af7f78ce0e866ba5e680f0b05f3d';
- /**
- * 坐标逆向解析 参考地址 https://lbs.amap.com/api/webservice/guide/api/georegeo#regeo
- *
- * @param $lngLat array 经纬度
- *
- * @return $address 解析地址
- * */
- public static function getAddress(array $lngLat){
- $url = "https://restapi.amap.com/v3/geocode/regeo?output=json&location=".$lngLat[0].",".$lngLat[1]."&key=".self::AK."&radius=100&extensions=all";
- $res = curl_request($url);
- $res = json_decode($res);
- $address = '';
- if($res->info == "OK"){
- $address = $res->regeocode->formatted_address;
- }
- return $address;
- }
- /**
- * 批量请求
- *
- *
- * */
- public static function batchRequest(array $ops){
- $url = "https://restapi.amap.com/v3/batch?key=".self::AK;
- $method = "post";
- $data = json_encode($ops);
- $res = curl_request($url,$method,$data);
- return $res;
- }
- /**
- * 批量坐标逆向解析
- * */
- public static function getAddressMany(array $arr){
- $params = [];
- foreach ($arr as $v){
- $params[] =['url'=>"/v3/geocode/regeo?output=json&location=".(empty($v) ? 0 : $v->lng) .",".(empty($v) ? 0 : $v->lat) ."&key=".self::AK."&radius=100&extensions=all"];
- }
- $res = self::batchRequest(['ops'=>$params]);
- return $res;
- }
- }
|