AK = sysconfig('baidu.map_ak'); } //wgs84转百度坐标 public function wgs84_to_baidu($location) { $url='https://api.map.baidu.com/geoconv/v1/?coords='.$location['lng'].','.$location['lat'].'&from=1&to=5&ak='.$this->AK; $result=json_decode(file_get_contents($url),true); $result = $result['result'][0]; if(isset($result['x'])){ $loc['lng']=$result['x']; $loc['lat']=$result['y']; return $loc; }else{ return false; } } //地址转经纬度 public function address_to_location($Address) { $Address=str_replace(' ','',$Address); $url='https://api.map.baidu.com/geocoding/v3/?address='.$Address.'&city=宜昌市&output=json&ak='.$this->AK; $result=json_decode(file_get_contents($url),true); if(isset($result['result']['location'])){ return $result['result']['location']; }else{ WLog('address_to_location',json_encode($result)); return false; } } // 经纬度转地址 public function location_to_address($location,$coordtype='wgs84ll') { $url = "http://api.map.baidu.com/reverse_geocoding/v3/?ak=".$this->AK."&output=json&coordtype=$coordtype&location=".$location['lat'].",".$location['lng']; $result = json_decode(file_get_contents($url),true); if($result['status']==0){ return $result['result']; }else{ return false; } } // 地点检索 public function getAddrList($query) { $query = str_replace(' ','',$query); if(!empty($query)){ $url = "https://api.map.baidu.com/place/v2/search?query=$query&output=json®ion=宜昌市&page_size=10&ak=".$this->AK; $result = json_decode(file_get_contents($url),true); if($result['status']==0){ $addressList = array_column($result['results'],'name'); if(!in_array($query,$addressList)){ $local = $this->address_to_location($query); if($local){ $result['results'][] = [ 'name' => $query, 'location' => $local, 'address' => $query ]; } } return $result['results']; }else{ WLog('getaddrlist',json_encode($result)); return false; } }else{ return false; } } } ?>