标签:php百度坐标转高德坐标
php处理表里存储的坐标进行转换
基于thinkphp3.2框架写的方法
public function gaoDe() {
set_time_limit(0); //防止超时
$VillageDb=D("Village");
$field="lat,lng,villageId";
$map[‘ajkId‘]=array(‘gt‘,1);
$map[‘lat‘]=array(‘gt‘,0);
$map[‘lng‘]=array(‘gt‘,0);
$data=$VillageDb->where($map)->select();//先把坐标和对应的id取出来
foreach ($data as $key=>$val){
$url="http://restapi.amap.com/v3/assistant/coordinate/convert?key=1030d03e5fa1aa9337ed6b92e43b7feb&locations=".$val[‘lat‘].",".$val[‘lng‘]."&coordsys=baidu"; //高德的key和接口转换地址
$data1= json_decode(file_get_contents($url)); //开始转换
$location=explode(‘,‘,$data1->locations); //取到坐标
$data=array();
$where[‘villageId‘]=$val[‘villageId‘];
$data[lat]=$location[0];
$data[lng]=$location[1];
//$result=$VillageDb->execute("update br_esf_village set lat = ".$data[$key][‘lat‘]." ,lng = ".$data[$key][‘lng‘]." where villageId=".$data[$key][‘villageId‘]."");
//if(!$result){$this->gaode();}
$result=$VillageDb->where($where)->save($data); // 保存数据
if(!$result){$this->gaode();} //失败的再次处理
}
}
本文出自 “PHP/Linux@HeFei” 博客,请务必保留此出处http://liang3391.blog.51cto.com/178205/1789576
标签:php百度坐标转高德坐标
原文地址:http://liang3391.blog.51cto.com/178205/1789576