利用百度地图采集大量某一区域经纬度信息
2016-09-26 16:46
253 查看
先在一定范围内生成经纬度随机数,再丢给百度地图反解析地址,正则匹配返回内容,作出判断,如果是我们的目标区域,则存入数据库(我主要是采集朝阳区内的经纬度信息,以下代码中我把省份等其他信息也拿下来了,第一次写博文,好紧张
)
)
<?php include_once "Connection.php"; include_once "autoload.php"; header("Content-type: text/html; charset=utf-8"); $db = NewADOConnection('mysql'); $db->Connect('localhost', 'root', '','chartdb'); $db->Execute("set names utf8;"); for ($i = 1; $i < 10000; $i++) { $coordone=116.4+randomOne(); $coordtwo =39.8+randomTwo(); $url = "http://api.map.baidu.com/geocoder?location=".$coordtwo.",".$coordone."&output=xml&key=aaa";//aaa处粘贴自己申请的百度api的key即可 $output = httpcurl($url); preg_match_all("/<lat.*?>(.*?)<\/lat>/", $output, $lat); preg_match_all("/<lng.*?>(.*?)<\/lng>/", $output, $lng); preg_match_all("/<formatted_address.*?>(.*?)<\/formatted_address>/", $output, $formatted_address); preg_match_all("/<business.*?>(.*?)<\/business>/", $output, $business); preg_match_all("/<street.*?>(.*?)<\/street>/", $output, $street); preg_match_all("/<district.*?>(.*?)<\/district>/", $output, $district); preg_match_all("/<city.*?>(.*?)<\/city>/", $output, $city); preg_match_all("/<province.*?>(.*?)<\/province>/", $output, $province); preg_match_all("/<cityCode.*?>(.*?)<\/cityCode>/", $output, $cityCode); $lat=$lat[1][0]; $lng=$lng[1][0]; $formatted_address=$formatted_address[1][0]; $business=$business[1][0]; $street=$street[1][0]; $district=$district[1][0]; $city=$city[1][0]; $province=$province[1][0]; $cityCode=$cityCode[1][0]; if ($district == "朝阳区"){ $nums= rand(0,50); insertToMySQL($db,$lat,$lng,$formatted_address,$business,$street,$district,$city,$province,$cityCode,$nums); } } function insertToMySQL($db,$lat,$lng,$formatted_address,$business,$street,$district,$city,$province,$cityCode,$nums){ $sql="insert into heatmap (lat,lng,formatted_address,business,street,district,city,province,citycode,nums) VALUES ('{$lat}','{$lng}','{$formatted_address}','{$business}','{$street}','{$district}','{$city}','{$province}','{$cityCode}','{$nums}')"; $db->Execute($sql); } function randomOne($min = 0, $max = 0.2) { return $min + mt_rand() / mt_getrandmax() * ($max - $min); } function randomTwo($min = 0, $max = 0.3) { return $min + mt_rand() / mt_getrandmax() * ($max - $min); } function httpcurl($url, $post_data = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url);//x curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $output = curl_exec($ch); curl_close($ch); return $output; } ?>
相关文章推荐
- Adroid利用百度地图将经纬度转换为地址信息
- Web项目实现通过经纬度获取城市信息---利用百度地图
- python 百度地图信息采集实例(包含经纬度)
- 利用HTML5定位功能获取经纬度,在根据经纬度利用百度地图获取位置信息
- 百度地图的反地址解析(通过经纬度查询地址信息)
- 百度地图_根据地图上标记位置获取街道信息,以及经纬度信息
- 地区经纬度信息获取(利用Google地图API获取)
- 百度地图5之根据经纬度查询地址信息(Android) .
- 利用cellID获取经纬度,地址信息
- 根据经纬度获取百度地图的详细地址信息
- 查找IP位置 \ c# 通过经纬度 查询地址、区域信息
- 灌入大量数据后手工采集统计信息的重要性
- 利用百度地图api通过城市地址等信息取经纬度
- 地区经纬度信息获取(利用Google地图API获取)
- MapView 百度地图 (锁定到以当前经纬度为中心点的显示区域和合适的显示范围 )
- android使用百度地图定位(获取当前经纬度和地址信息)
- 百度地图之根据经纬度信息获取地址方法
- 百度地图_根据地图上标记位置获取街道信息,以及经纬度信息
- 如何利用google 地图查询经纬度信息
- 百度地图经纬度转换+反地址解析+显示可视区域内标注点+地图自动刷新+标注的聚合