JS crawling high moral map address information (latitude and longitude surrounding facilities)

Requirements: given name into one million cells and the corresponding city information, access to its peripheral facility information (transport, health, education and living facilities) by high German

High German JS API

JS API crawling inspiration from the high moral development support, of course, you can also call api service provides access to high German address information directly, but there is a number of restrictions api service. JS API calls and the number of times is not limited by a crawling my verification crawling frequency control node 500 ms is not limited.
https://lbs.amap.com/api/javascript-api/example/poi-search/keywords-search
image.png

High moral principles address access to information

The introduction of high moral AMap objects through JS, call the relevant method to obtain the corresponding data. JS call display high moral map information is surrounding this logic.

Ready to work

Sign up maps high moral account -> create console application -> Application Key
required to apply Key before they can use in their own high moral js js code
Application Key.png

Data Capture

Data acquisition process .png

Data Service API:
read the cell data into the list each time a request to return data from a pop list, so that the front end of the plurality of nodes can simultaneously gripping a plurality of tasks.

Data Acquisition:
To use the high moral need to introduce the following two js, which is the key high German official website of the application key

<script src="http://cache.amap.com/lbs/static/jquery-1.9.1.js"></script>
<script src="http://webapi.amap.com/maps?v=1.3&key=************&plugin=AMap.ArrivalRange,AMap.Scale,AMap.Geocoder,AMap.Transfer,AMap.Autocomplete" id="amap_key"></script>

get request to obtain cell data, create high moral objects

$.ajax({
        type:"get", 
        url:"http://127.0.0.1:5075/api/community",
        dataType:"json",
        contentType:"application/json",
        success:function(data){ 
            params = data;
            console.log('Getapi data',data)
            MAP = new AMap.Map("container", {
                resizeEnable: true
            });
            getAddress(data)
        }
     });

High German call JS cell information search elements:
1. In the process configuration configured AMap.service location query class
2. Location method calls the search query results returned class Result
3. returned results using the latitude and longitude of the cell to acquire peripheral data call searchNearBy

AMap.service(["AMap.PlaceSearch"], function() {
            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 3,
                pageIndex: 1,
                city: city, //城市
                map: MAP,
                type:"商务住宅|门牌信息",
                citylimit:true,
                extensions:"all",
                // panel: "panel"
            });
            //关键字查询
     
            placeSearch.search(keyword, function(status, result) {
                console.log('getAddress info',result.info,result);
                
                searchNearBy(city,cpoint,keyword);
            });
        });

Search results for front-end printing, access to information is very detailed, including provincial cities and counties and their coding, and latitude and longitude information:
Print results .png

The complete code

Save the codes to index.html, python (python -m SimpleHTTPServer 8000 ) http service to start locally in the same directory.
Browser requests: HTTP: // localhost:? 8000 Key = ***************************

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>高德房源地址获取</title>
    <script src="http://cache.amap.com/lbs/static/jquery-1.9.1.js"></script>
    <!-- <script src="http://webapi.amap.com/maps?v=1.3&key=01aa9e655798548a06c7697db75a9903&plugin=AMap.ArrivalRange,AMap.Scale,AMap.Geocoder,AMap.Transfer,AMap.Autocomplete" id="amap_key"></script> -->
    <script type="text/javascript">
        // 根据请求url获取小区信息 及构造高德js
        function GetRequest() {
           var url = decodeURIComponent(location.search); //获取url中"?"符后的字串  
           var theRequest = new Object();  
           if (url.indexOf("?") != -1) {  
              var str = url.substr(1);  
              strs = str.split("&");  
              for(var i = 0; i < strs.length; i ++) {  
                 theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);  
              }  
           }  
           return theRequest;  
        }

        var params = GetRequest();
        var key = params.key;
       // 动态构造引入高德js
        var mapSrc = 'http://webapi.amap.com/maps?v=1.3&key='+key+'&plugin=AMap.ArrivalRange,AMap.Scale,AMap.Geocoder,AMap.Transfer,AMap.Autocomplete';
        console.log(mapSrc)
        document.write('<script src='+mapSrc+'></sc' + 'ript>')
    </script>

</head>

<body id='body'>
<div id="container"></div>

<script type="text/javascript">
    function send_mongodb(save_data){
        save_url =  decodeURIComponent(location.href)+'&'+params.id; 
        console.log('amap_data done:',save_data,save_url)
        params = {
          "_template": "amap_gps_nearby",
          "_title": save_data.community+"周边信息",
          "_timestamp": Date.parse(new Date()),
          "_hostname": '',
          "_url": save_url,
          "_data": {
            "data":save_data
            },
        "_timestampstr": new Date()
        }
        $.ajax({
            type:"POST", 
            url:"http://127.0.0.1:5125/upload",
            dataType:"json",
            contentType:"application/json",
            data:JSON.stringify(params), 
            success:function(data){ 
                console.log('POST mongodb:',data)
            }
         });
        setTimeout(function(){
            flag_over = true;
            // location.reload();
        }, 400);
        
    }

    function getAddress(params) {
        // alert('')
        var city = params.city;
        var district = params.district;
        var keyword = params.xiaoqu;
        var xiaoqu_code = params.xiaoqu_code;
        var xiaoqu = keyword;
        console.log('---------------------',city,keyword);

        AMap.service(["AMap.PlaceSearch"], function() {
            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 3,
                pageIndex: 1,
                city: city, //城市
                map: MAP,
                type:"商务住宅|门牌信息",
                citylimit:true,
                extensions:"all",
                // panel: "panel"
            });
            //关键字查询
     
            placeSearch.search(keyword, function(status, result) {
                if(status==0){
                    console.log('请求失败')
                    return
                }
                console.log('getAddress info',result.info,result);
                if(keyword!='' && result.poiList &&result.poiList.pois.length>0){
                    var detail = [];
                    var detail = result.poiList.pois[0];
                    for(i=0; i<result.poiList.pois.length; i++){
                        // 对返回的数据通过区县进行二次筛选
                        var item = result.poiList.pois[i];
                        if(item.adname && district && (item.adname.indexOf(district)!=-1 || district.indexOf(item.adname)!=-1) &&
                            (xiaoqu.indexOf(item.name)!=-1 || item.name.indexOf(xiaoqu)!=-1)){
                            detail = item;
                            break;
                        }
                    }
                    var cpoint = [detail["location"]["lng"],detail["location"]["lat"]];
                    save_data = {"city":city,"district":district,"community":xiaoqu, "community_code":xiaoqu_code,"detail":detail}
                    searchNearBy(city,cpoint,keyword);
                }else{
                    flag_over = true;
                    console.log(keyword+' not find in amap');
                    // location.reload();
                }
            });
        });
    }

    function searchNearBy(city,cpoint,keyword){
        console.log('searchNearBy:',city,cpoint,keyword)
        var placeSearchNearBy = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 5,
                type: '',
                pageIndex: 1,
                city: city, //城市
                citylimit:true,
                map: MAP,
            });
        var nearby = {};
        // len = 30;
        var types = [
            {'subway':'地铁站'},{'bus':'公交车站'},{'parking_lot':'停车场'},{'other_traffic':'飞机场|火车站'},
            {'kids_school':'幼儿园'},{'primary_school':'小学'},{'middle_school':'初中'},{'high_school':'高等院校'},{'college':'大学'},{'train_school':'培训机构'},{'library':'图书馆'},{'science_museum':'科技馆'},{'AAA_hospital':'三级甲等医院'},{'special_hospital':'专科医院'},{'hospital':'综合医院'},{'clinic':'诊所'},{'pharmacy':'医药保健销售店'},{'shopping':'商场'},{'store':'便民商店|便利店'},{'supermarket':'超级市场'},{'comprehensive_market':'综合市场'},{'bank':'银行'},{'ATM':'ATM'},{'food':'中餐厅|外国餐厅|快餐厅'},{'drink':'咖啡厅|茶艺馆|冷饮店|甜品店'},{'park':'公园'},{'movies':'电影院'},{'sports':'运动场馆'},{'entertainment':'娱乐场所'},{'gym':'健身中心'}
            ]

        Search(placeSearchNearBy, types)
        function Search(placeSearchNearBy, types){
            if(types.length==0){
                flagSuccess = true;
                save_data['nearby'] = nearby;
                send_mongodb(save_data);
                return
            }
            var item = types.pop();
            for(var name in item){
                type = item[name]
            }
            placeSearchNearBy.setType(type);
            placeSearchNearBy.searchNearBy('', cpoint, 5000, function(status, result) {
                if(result.poiList && result.poiList.pois.length>0){
                    nearby[name] = result.poiList.pois;
                }
                else{
                    nearby[name] = [];
                }
                setTimeout(function(){
                    Search(placeSearchNearBy, types)
                }, 400);
                
            });
        }
    }

    save_data = {};

    setInterval(function(){
        location.reload();
    }, 1000*60*10);

    $.ajax({
            type:"get", 
            url:"http://127.0.0.1:5075/api/community",
            dataType:"json",
            contentType:"application/json",
            success:function(data){ 
                params = data;
                console.log('Getapi data',data)

                setTimeout(function(){
                    MAP = new AMap.Map("container", {
                        resizeEnable: true
                    });
                    getAddress(data)

                }, 400*10);
            }
         });

</script>
</body>
</html>

Guess you like

Origin www.cnblogs.com/i-love-python/p/11562892.html