Conversion of the coordinates stored in the PHP processing table
Method of writing based on thinkphp3.2 framework
Public Function Gaode () {
Set_time_limit (0); Prevent timeouts
$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 ()///first remove the coordinates and the corresponding ID
foreach ($data as $key = = $val) {
$url = "http://restapi.amap.com/v3/assistant/coordinate/convert?key=1030d03e5fa1aa9337ed6b92e43b7feb& Locations= ". $val [' lat '].", ". $val [' LNG ']." &coordsys=baidu "; The key and interface conversion address of the German
$data 1= Json_decode (file_get_contents ($url)); Start conversion
$location =explode (', ', $data 1->locations); Take the coordinates
$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); Save data
if (! $result) {$this->gaode ();}//Failed re-processing
}
}
This article is from the "php/[email protected]" blog, be sure to keep this source http://liang3391.blog.51cto.com/178205/1789576
PHP Baidu coordinates to the German coordinates