百度地图接口

  • T4_561052
    了解作者
  • 4.6KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-16 09:33
    上传日期
NULL 博文链接:https://hudeyong926.iteye.com/blog/2236904
map.zip
  • Map.class.php
    2.1KB
  • Maps.class.php
    18KB
内容介绍
<?php class Maps{ public $token; public $apikey; public $isamap; public $key; public $amap; public function __construct($token) { $this->token=$token; //$this->assign('token',$this->token); $this->apikey=C('baidu_map_api'); //$this->assign('apikey',$this->apikey); // if (C('baidu_map')){ $this->isamap=0; }else { $this->isamap=1; $this->amap=new amap(); } } //公司静态地图 public function staticCompanyMap(){ $amap=$this->amap; //main company $company_model=M('Company'); $where=array('token'=>$this->token); $thisCompany=$company_model->where($where)->order('isbranch ASC')->find(); //branches $where['isbranch']=1; $companies=$company_model->where($where)->order('taxis ASC')->select(); // $return=array(); //http://restapi.amap.com/v3/staticmap?location=116.48482,39.94858&zoom=10&size=440*280&labels=%E6%9C%9D%E9%98%B3%E5%85%AC%E5%9B%AD,2,0,16,0xFFFFFF,0x008000:116.48482,39.94858&key=ee95e52bf08006f63fd29bcfbcf21df0 //$imgUrl='http://api.map.baidu.com/staticimage?center='.$thisCompany['longitude'].','.$thisCompany['latitude'].'&width=640&height=320&zoom=11&markers='.$thisCompany['longitude'].','.$thisCompany['latitude'].'&markerStyles=l,1&t=gdf.png'; if (!$this->isamap){ $imgUrl='http://api.map.baidu.com/staticimage?center='.$thisCompany['longitude'].','.$thisCompany['latitude']; $link=C('site_url').'/index.php?g=Wap&m=Company&a=map&token='.$this->token; }else { $imgUrl=$amap->staticMap($thisCompany['longitude'],$thisCompany['latitude'],$thisCompany['name']); $link=$amap->getPointMapLink($thisCompany['longitude'],$thisCompany['latitude'],$thisCompany['name']); } $titleStr=$thisCompany['name'].'地图'; if ($companies){ $titleStr='1.'.$titleStr; } $return[]=array($titleStr,"电话:".$thisCompany['tel']."\r\n地址:".$thisCompany['address']."\r\n回复“开车去”“步行去”或“坐公交”获取详细线路\r\n点击查看详细",$imgUrl,$link); if ($companies){ $i=2; $sep=''; foreach ($companies as $thisCompany){ if (!$this->isamap){ $imgUrl='http://api.map.baidu.com/staticimage?center='.$thisCompany['longitude'].','.$thisCompany['latitude'].'&width=80&height=80&zoom=11&markers='.$thisCompany['longitude'].','.$thisCompany['latitude'].'&markerStyles=l,'.$i; $link=C('site_url').'/index.php?g=Wap&m=Company&a=map&companyid='.$thisCompany['id'].'&token='.$this->token; }else { $imgUrl=$amap->staticMap($thisCompany['longitude'],$thisCompany['latitude'],$thisCompany['name'],200,200); $link=$amap->getPointMapLink($thisCompany['longitude'],$thisCompany['latitude'],$thisCompany['name']); } //$imgUrl=$thisCompany['logourl']; $return[]=array($i.'.'.$thisCompany['name'].'地图',"电话:".$thisCompany['tel']."\r\n地址:".$thisCompany['address']."\r\n点击查看详细",$imgUrl,$link); $i++; } //使用操作 $imgUrl=$thisCompany['logourl']; $return[]=array('回复“最近的”查看哪一个离你最近,或者回复“开车去+编号”“步行去+编号”或“坐公交+编号”获取详细线路',"电话:".$thisCompany['tel']."\r\n地址:".$thisCompany['address']."\r\n点击查看详细",$imgUrl,$link); } return array($return,'news'); } public function walk($x,$y,$companyid=1){ // $company_model=M('Company'); $where=array('token'=>$this->token); $companies=$company_model->where($where)->order('isbranch ASC,taxis ASC')->select(); $i=intval($companyid)-1; $thisCompany=$companies[$i]; // if (!$this->isamap){ $rt=json_decode(file_get_contents('http://api.map.baidu.com/direction/v1?region=&mode=walking&origin='.$x.','.$y.'&destination='.$thisCompany['latitude'].','.$thisCompany['longitude'].'&output=json&ak='.$this->apikey),1); if (is_array($rt)){ $return=array(); // //$imgUrl='http://api.map.baidu.com/staticimage?center='.$thisCompany['longitude'].','.$thisCompany['latitude'].'&width=640&height=320&zoom=13&markers='.$thisCompany['longitude'].','.$thisCompany['latitude']; $imgUrl='http://api.map.baidu.com/staticimage?center='.$thisCompany['longitude'].','.$thisCompany['latitude']; //长度 $distance=$rt['result']['routes'][0]['distance']; if ($distance>1000){ $distanceStr=(round($distance/1000,2)).'公里'; }else { $distanceStr=$distance.'米'; } //耗时 $duration=$rt['result']['routes'][0]['duration']/60; if ($duration>60){ $durationStr=intval($duration/100).'小时'; if ($duration%60>0){ $durationStr.=($duration%60).'分钟'; } }else { $durationStr=intval($duration).'分钟'; } //路书 $stepStr=""; $steps=$rt['result']['routes'][0]['steps']; if ($steps){ $i=1; foreach ($steps as $s){ $stepStr.="\r\n".$i.".".str_replace(array('<b>','</b>'),'',$s['instructions']); $i++; } } $return[]=array('步行到'.$thisCompany['name'].'行程有'.$distanceStr.',大概需要'.$durationStr,"具体方案:".$stepStr,$imgUrl,C('site_url').'/index.php?g=Wap&m=Company&a=walk&longitude='.$y.'&latitude='.$x.'&companyid='.$thisCompany['id'].'&token='.$this->token); return array($return,'news'); }else { return array('没有相应的路书','text'); } }else { $imgUrl=$this->amap->staticMap($thisCompany['longitude'],$thisCompany['latitude'],$thisCompany['name']); $rt=$this->amap->walking($y.','.$x,$thisCompany['longitude'].','.$thisCompany['latitude']); if ($rt['route']){ //路书 $stepStr=""; $steps=$rt['route']['paths'][0]; $distanceStr=$this->_getDistance($steps['distance']); $durationStr=$this->_getTime($steps['duration']); if ($steps['steps']){ $i=1; foreach ($steps['steps'] as $s){ $stepStr.="\r\n".$i.".".str_replace(array('<b>','</b>'),'',$s['instruction']); $i++; } } $link=$this->amap->navi($y.','.$x,$thisCompany['longitude'].','.$thisCompany['latitude'],$thisCompany['name'],'walk'); $return[]=array('步行到'.$thisCompany['name'].'行程有'.$distanceStr.',大概需要'.$durationStr,"具体方案:".$stepStr,$imgUrl,$link); return array($return,'news'); }else { return array($rt['info'],'text'); } } } public function drive($x,$y,$companyindex=1){ // $company_model=M('Company'); $where=array('token'=>$this->token); $companies=$company_model->where($where)->order('isbranch ASC,taxis ASC')->select(); $i=intval($companyindex)-1; $thisCompany=$companies[$i]; if (!$this->isamap){ // $rt=json_decode(file_get_contents('http://api.map.baidu.com/direction/v1?mode=driving&origin='.$x.','.$y.'&destination='.$thisCompany['latitude'].','.$thisCompany['longitude'].'&origin_region=&destination_region=&output=json&ak='.$this->apikey),1); if (is_array($rt)){ $return=array(); // //$imgUrl='http://api.map.baidu.com/staticimage?center='.$thisCompany['longitude'].','.$thisCompany['latitude'].'&width=640&height=320&zoom=13&markers='.$thisCompany['longitude'].','.$thisCompany['latitude']; $imgUrl='http://api.map.baidu.com/staticimage?center='.$thisCompany['longitude'].','.$thisCompany['latitude']; //长度 $distance=$rt['result']['routes'][0]['distance']; if ($distance>1000){ $distanceStr=(round($distance/1000,2)).'公里'; }else { $distanceStr=$distance.'米'; } //耗时 $duration=$rt['result']['routes'][0]['duration']/60; if ($duration>60){ $durationStr=intval($duration/100).'小时'; if ($duration%60>0){ $durationStr.=($duration%60).'分钟'; } }else { $durationStr=intval($duration).'分钟'; } //路书 $stepStr=""; $steps=$rt['result']['routes'][0]['steps']; if ($steps){ $i=1; foreach ($steps as $s){
评论
    相关推荐