您的位置:首页 > 编程语言 > PHP开发

php百度坐标转高德坐标

2016-06-15 16:37 411 查看
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 百度 坐标