Write a PHP script today to starters the region name of the response from the database and then query the name of the kindergarten for accurate latitude and longitude. Each time the resulting latitude and longitude enters the changes in the database.
Over 70,000 data takes one hours to complete. I have to say that curl results more quickly than file_getcoents. Not much to say directly on the code
<?Phpdate_default_timezone_set (' Asia/chongqing ');Header(' content-type:text/html; Charset=utf-8 ');Ini_set(' Display_errors ', 1);error_reporting(E_all);Set_time_limit(0);/** * @author GF * Get latitude and longitude modification data * Class Importkindgarten*/classimportkindgarten{Private $dbhost= ' 127.0.0.1 '; Private $dbuser= ' Root '; Private $DBPW= ' 123 '; Private $dbname= ' Mypolyguide '; Private $dbcharset= ' UTF8 '; Private $write _db=NULL; Public function__construct () {$this-Db_write_link (); } /** * Connection database * @return Null|resource*/ Public functionDb_write_link () {$this->write_db =mysql_connect($this->dbhost,$this->dbuser,$this-DBPW); if(!$this-write_db) { die(' Could not connect: '.Mysql_error()); } mysql_query(' SET character_set_connection= '.$this->dbcharset. ', character_set_results= '.$this->dbcharset. ', Character_set_client=binary ',$this-write_db); mysql_query(' SET names UTF8 ',$this-write_db); mysql_select_db($this->dbname,$this-write_db); return $this-write_db; } /** * Execute dead loop for query modification*/ Public functionroundkglist () {$i= 0; while(true) { $res=$this-getkglist (); if(Empty($res[' Kgdata '])) { Break; } Else { if(!Empty($res[' Kgdata ']))foreach($res[' Kgdata '] as $k 1=$v 1) { $info=$this->getareanamebyid ($v 1[' Provinceid ']); $area=$info[0]; $address=$v 1[' Kgname ']; $RETURNARR=$this->curlgetweb ($area,$address); $kgPosition=implode(‘,‘,$RETURNARR); $updatesql= "UPDATE kindgartenbak SET lng= ' {$RETURNARR[' LNG ']} ', lat= ' {$RETURNARR[' Lat ']} ', kgposition= ' {$kgPosition} ', runflag= ' 1 ' WHERE kgid={$v 1[' Kgid ']} "; mysql_query($updatesql,$this-write_db); $i++; } Else { Break; } } } } /** * Get list * @return mixed*/ Public functiongetkglist () {$sql= ' SELECT kgid,provinceid,kgname from Kindgartenbak WHERE Deleteflag = 1 and Status = 2 and Runflag = 0 ORDER by Kgid DESC LIMIT 100 '; $query=mysql_query($sql,$this-write_db); while($result=Mysql_fetch_array($query,Mysql_assoc)) { $res[' Kgdata '] [] =$result; } return $res; } /** Fetch CITY * @return Mixed*/ Public functionGetareanamebyid ($provinceId) { $sql= ' SELECT areaname from area WHERE id = '.$provinceId; $query=mysql_query($sql,$this-write_db); $info=Mysql_fetch_row($query); if(!Empty($info)) { return $info; } Else { return false; } } /** * from Baidu Map API with Curl to get latitude and longitude * Array form return*/ Public functionCurlgetweb ($area,$address) { $URL= "http://api.map.baidu.com/geocoder?address=".Trim($area).Trim($address)." &output=json&key=96980ac7cf166499cbbcc946687fb414 "; $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$URL); curl_setopt ($ch, Curlopt_header,false); curl_setopt ($ch, Curlopt_returntransfer, 1);//If this line is commented out, it will be output directly . $result=curl_exec ($ch); Curl_close ($ch); $infolist=json_decode ($result); $array=Array(); if(isset($infolist->result->location) &&!Empty($infolist->result->Location )) { $array=Array( ' LNG ' =$infolist->RESULT->LOCATION->LNG, ' lat ' =$infolist->result->location->lat, ); return $array; } Else { return false; } }}$start _date=Date(' y-m-d h:i:s ');$start=Microtime(true);$db=NewImportkindgarten ();$i=$db-roundkglist ();$end=Microtime(true);Echo' Reset latitude and Longitude: '.$start _date.‘ ----Time--'. ($end-$start).‘ ----A total update ('.$i.‘) Reviews;?>
A PHP script, through Curl first get Baidu Map API generated latitude and longitude, and then change the data in the database.