php百度坐标转高德坐标

发布时间:2020-06-11 14:28:33 作者:liang3391
来源:网络 阅读:1390

   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();} //失败的再次处理

          

      }

}


推荐阅读:
  1. 百度地图坐标转换
  2. android 百度地图坐标类型setCoorType

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php 百度 坐标

上一篇:PHP中extract的用法

下一篇:PHP怎么关闭页面的错误提示

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》