Commit 96256c3d authored by zhuwei's avatar zhuwei

获取商圈经纬度

parent a62d0035
......@@ -10,6 +10,7 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\index\service\HouseService;
use app\model\GBusinessDistrict;
use app\model\Regions;
......@@ -42,6 +43,9 @@ class BusinessDistrict extends Basic
} else {
$business->save($data);
$num = $business->id;
/*获取商圈经纬度*/
$house = new HouseService();
$house->setCityLatAadLng($num,$params['business'], $params['city']);
}
if ($num) {
......
......@@ -12,6 +12,7 @@ namespace app\index\service;
use app\api_broker\service\PushMessageService;
use app\index\validate\HouseValidate;
use app\model\AAgents;
use app\model\GBusinessDistrict;
use app\model\GHouseFile;
use app\model\GHouses;
use app\model\GHousesExt;
......@@ -363,4 +364,55 @@ class HouseService
return $result;
}
/**
* 批量设置商圈的经纬度
*/
public function setCityLatAadLng($id,$name, $city){
if(!$id or !$name or !$city ){
return false;
}
$model = new GBusinessDistrict();
$res = $this->getLatLng($name, $city);
if($res){
$longitude = $res['lng'];//'经度'
$latitude = $res['lat'];//'维度'
}else{
$longitude = '';//'经度'
$latitude = '';//'维度'
}
$insert=[];
$insert["id"] = $id;
$insert["longitude"] = $longitude;
$insert["latitude"] = $latitude;
$model->updateBusinessDistrict($insert);//int(1)
return true;
}
/**
* @param string $address 地址
* @param string $city 城市名
* @return array
*/
function getLatLng($address='',$city='')
{
$result = array();
$ak = 'eqkGg4WQehHn4k7ssWZTv8RPvydUm35s';//您的百度地图ak,可以去百度开发者中心去免费申请
$url ="http://api.map.baidu.com/geocoder/v2/?callback=renderOption&output=json&address=".$address."&city=".$city."&ak=".$ak;
$data = file_get_contents($url);
$data = str_replace('renderOption&&renderOption(', '', $data);
$data = str_replace(')', '', $data);
$data = json_decode($data,true);
if (!empty($data) && $data['status'] == 0) {
$result['lat'] = $data['result']['location']['lat'];
$result['lng'] = $data['result']['location']['lng'];
return $result;//返回经纬度结果
}else{
return null;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment