您好,登錄后才能下訂單哦!
php處理表里存儲的坐標進行轉(zhuǎn)換
基于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();//先把坐標和對應(yīng)的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和接口轉(zhuǎn)換地址
$data1= json_decode(file_get_contents($url)); //開始轉(zhuǎn)換
$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); // 保存數(shù)據(jù)
if(!$result){$this->gaode();} //失敗的再次處理
}
}
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。