/** * 得到模糊坐标 */ public function getPoint($area, $address, $key) { //百度地图接口:http://api.map.baidu.com/geocoder/v2/address=地址&output=输出格式类型&key=用户密钥&city=城市名 //需要4个参数:address详细地址,output格式,ak接口密匙,city城市名 //地区转换 // $areaModel = AreaModel::find($area); // $areaname = $areaModel ? $areaModel->cityname : ''; $cityModel = new AreaModel(); $areaname = $area ? $cityModel->getAreaName($area) : ''; //请求接口,返回数据 $apiUrl = 'http://api.map.baidu.com/geocoder/v2/'; $curl = new \Curl\Curl(); $curl->setHeader('X-Authorization', $key); $curl->get($apiUrl, array('address' => $address, 'output' => 'json', 'ak' => $key, 'city' => $areaname)); $response = json_decode($curl->response); $response = \App\Tools::objectToArray($response); if ($response['status'] != 0) { if ($response['status'] == 1) { echo "<script>alert('地址有误或百度地图服务器内部有变!');history.go(-1);</script>"; exit; } elseif ($response['status'] == 2) { echo "<script>alert('地区或地址有误!');history.go(-1);</script>"; exit; } elseif ($response['status'] == 3) { echo "<script>alert('权限校验失败!');history.go(-1);</script>"; exit; } elseif ($response['status'] == 4) { echo "<script>alert('配额校验失败!');history.go(-1);</script>"; exit; } elseif ($response['status'] == 5) { echo "<script>alert('百度地图密匙错误!');history.go(-1);</script>"; exit; } elseif ($response['status'] == 101) { echo "<script>alert('服务禁用!');history.go(-1);</script>"; exit; } elseif ($response['status'] == 102) { echo "<script>alert('百度地图密匙权限不足!');history.go(-1);</script>"; exit; } elseif ($response['status'] == "2xx") { echo "<script>alert('无权限!');history.go(-1);</script>"; exit; } elseif ($response['status'] == "3xx") { echo "<script>alert('配额错误!');history.go(-1);</script>"; exit; } } return $response['result']['location']; }
public function query() { $data = new \stdClass(); //type==1公司简介,2历程,3新闻,4资讯,5服务,6团队,7招聘,21单页 $data->abouts = ComFuncModel::where('type', '<', 5)->where('cid', $this->cid)->get(); $data->products = GoodsModel::where('genre', 1)->where('type', 4)->get(); $data->teams = ComFuncModel::where('type', 6)->where('cid', $this->cid)->get(); $data->jobs = ComFuncModel::where('type', 7)->where('cid', $this->cid)->get(); //公司联系方式 $data->contactFields = ['area', 'point', 'address', 'tel', 'qq', 'web', 'fax', 'email']; $data->contactFieldNames = ['地区', '坐标', '地址', '电话', 'qq', '网址', '传真', '邮箱']; $data->contact = 0; $comMainModel = CompanyModel::find($this->cid); $comMainModel = Tools::objectToArray($comMainModel); foreach ($data->contactFields as $contactField) { if ($comMainModel[$contactField]) { $data->contact++; } } $data->parts = GoodsModel::where('genre', 2)->where('type', 4)->get(); $data->firms = ComFuncModel::where('type', 5)->where('cid', $this->cid)->get(); return $data; }
/** * 由ip获得所在城市 */ public static function getCityByIp($ip = '') { $address = ''; if ($ip && substr($ip, 0, 7) != '192.168') { $key = 'Tj1ciyqmG0quiNgpr0nmAimUCCMB5qMk'; //自己申请的百度地图api的key $curl = new \Curl\Curl(); $apiUrl = 'http://api.map.baidu.com/location/ip'; $curl->post($apiUrl, array('ak' => $key, 'ip' => $ip)); $response = $curl->response; $response = \App\Tools::objectToArray($response); if ($response['status'] == 0) { $address = $response['content']['address']; } } elseif ($ip && substr($ip, 0, 7) == '192.168') { $address = '浙江省 杭州市 滨江区'; } elseif (!$ip) { $address = '未知'; } return $address; }