Random image mariadb inserts 0.1 million data, including longitude and latitude, and calls Baidu mapAPI to obtain province-PHP source code

Source: Internet
Author: User
The random image mariadb inserts 0.1 million of the data, including the longitude and latitude, and calls Baidu mapAPI to obtain the data required for a province Project. here, we simulate inserting 10000 of the data.

The data includes the longitude and latitude (uploaded by the app). here, you need to call Baidu API to obtain the identity of the latitude and longitude, so that echarts can be called later to draw the distribution of provinces on the national map.

Here, the longitude and latitude and time are randomly generated,

Some details are not very well handled. it doesn't matter. just insert data randomly.

 query("delete from message");    function suijishijian()    {        $month=array('0','01','02','03','04','05','06','07','08','09','10','11','12');        $days=array('0','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');        $hour=array('0','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','00');        $fz=array("","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59");        $day=array(                 "01"=>"31",                 "02"=>"28",                 "03"=>"31",                 "04"=>"30",                 "05"=>"31",                 "06"=>"30",                 "07"=>"31",                 "08"=>"31",                 "09"=>"30",                 "10"=>"31",                 "11"=>"30",                 "12"=>"31");        $y=rand(2010,2013);        $m=$month[rand(1,12)];        $d=$days[rand(1,$day["$m"])];        $h=$hour[rand(1,24)];        $mm=$fz[rand(1,60)];        $s=$fz[rand(1,60)];        return "$y-$m-$d $h:$mm:$s\\n";    }    function floadNumber($min,$max)    {         return $min + mt_rand() / mt_getrandmax() * ($max - $min);      }    function shengfen($jd,$wd)    {        $url="http://api.map.baidu.com/geocoder?location={$wd},{$jd}&output=json";        $json=json_decode(file_get_contents($url),TRUE);        return $json['result']['addressComponent']['province'];    }    for($i=1;$i<10000;$i++)    {        $zid=rand(1,99999);        $time=suijishijian();        $jingdu=floadNumber(100,120);        $weidu=floadNumber(30,40);        $province=shengfen($jingdu,$weidu);        $lid=rand(1,13);        $type=rand(0,3);        $tag=rand(1,4);        $sbh=md5(time());        $sql="insert into `tongji` (zid,time,jingdu,weidu,province,lid,type,tag,sbh) VALUES ('{$zid}','{$time}','{$jingdu}','{$weidu}','{$province}','{$lid}','{$type}','{$tag}','{$sbh}')";        $link->query($sql);          echo $sql."\\n";    }    $link->close();?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.