{"id":255,"title":"\u767e\u5ea6\u5730\u56fe\u5b9a\u4f4d\u53ca\u5750\u6807\u8f6c\u6362","good":0,"bad":0,"hit":2994,"created_at":"2017-02-13 10:13:15","content":"

\u6700\u8fd1\u8981\u641e\u4e00\u4e2a\u6d3b\u52a8\uff0c\u5173\u4e8e\u95e8\u5e97\u5b9a\u4f4d\u7684\uff1a<\/p>

\u5c06csv\u6587\u4ef6\u4e2d\u7684\u4e2d\u6587\u5730\u5740\u8f6c\u6362\u6210\u767e\u5ea6\u5730\u56fe\u7ecf\u7eac\u5750\u6807\uff1a<\/p>

$oneline\u5bf9\u5e94csv\u6587\u4ef6\u4e2d\u7684\u5730\u884c\u5730\u5740<\/p>

public function baiduMap(){    set_time_limit(0);    $file=APP_PATH.'ctrl\/love.csv';    $handle=fopen($file,'r');    if($handle){        $i=0;        while(!feof($handle)){            $oneline=fgetss($handle);            if($oneline){                \/\/var_dump($oneline);                \/\/$oneline=str_replace('\\r\\n','',$oneline);                if(strlen($oneline)>2){                    if($i<400){                        $url='http:\/\/api.map.baidu.com\/geocoder\/v2\/?output=json&ak=\u6362\u6210\u4f60\u81ea\u5df1\u7684key<\/a> &address='.$oneline;                        $str=file_get_contents($url);                        sleep(1);\/\/\u4f11\u606f\u4e00\u4e0b\uff0c\u9632\u6b62\u670d\u52a1\u5668\u6302\u6389                        if($str){                            $arr=json_decode($str,true);                            \/\/self::p($arr);                            $x=$arr['result']['location']['lng'];                            $y=$arr['result']['location']['lat'];                            $sql="insert into `table` values(null,$oneline,$x,$y)<br\/>";                            echo $sql;                        }else{                            echo $i.$oneline.'<br\/>';                        }                    }                    $i++;                }            }        }    }}<\/p>

<\/p>

\u767e\u5ea6\u5730\u56fe\u5b9a\u4f4d\u7684\u4e00\u4e9b\u63a5\u53e3\uff1a<\/p>

\u4e2d\u6587\u5730\u5740\u8f6c\u7ecf\u7eac\u5ea6\u5750\u6807\uff1ahttp:\/\/api.map.baidu.com\/geocoder\/v2\/?output=json&ak=\u4f60\u81ea\u5df1\u7684key&address=\u4e2d\u6587\u5730\u5740\u6839\u636e\u7ecf\u7eac\u5ea6\u5b9a\u4f4d\u5730\u5740\uff1ahttp:\/\/lbsyun.baidu.com\/jsdemo.htm#i8_4\u70b9\u51fb\u5730\u56fe\u83b7\u53d6\u5750\u6807\uff1ahttp:\/\/lbsyun.baidu.com\/jsdemo.htm#f0_3\u7ed8\u5236\u70b9\u7ebf\u9762\uff1ahttp:\/\/lbsyun.baidu.com\/jsdemo.htm#f0_7\u767e\u5ea6\u5730\u56fe\u5730\u70b9\u6807\u6ce8\u53ca\u7ea0\u9519\uff1ahttp:\/\/i.map.baidu.com\/api\/page\/poicorrect\/addpoipc?business_trigger=8&city_id=301&poi_name=%E4%B8%AD%E5%B1%B1%E4%B8%AD%E5%AD%A6-%E5%85%AC%E4%BA%A4%E8%BD%A6%E7%AB%99<\/a><\/p>

<\/p>

<\/p>

<\/p>

\u4e00\u4e2a\u6bd4\u8f83\u5b8c\u6574\u7684\u7ecf\u5e38\u7528\u5230\u7684\u767e\u5ea6\u5730\u56fe\u793a\u4f8b\uff1a<\/p>

<!DOCTYPE html><html><head>    <meta http-equiv="Content-Type" content="text\/html; charset=utf-8" \/>    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" \/>    <style type="text\/css">    body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"\u5fae\u8f6f\u96c5\u9ed1";}    <\/style>    <script type="text\/javascript" src="http:\/\/api.map.baidu.com\/api?v=2.0&ak=\u4f60\u81ea\u5df1\u7684key"><\/script>    <!--\u6d4b\u8ddd\u79bb\u7528-->    <script type="text\/javascript" src="http:\/\/api.map.baidu.com\/library\/DistanceTool\/1.2\/src\/DistanceTool_min.js"><\/script>    <title>\u5730\u56fe\u5c55\u793a<\/title><\/head><body>    <div id="allmap"><\/div><\/body><\/html><script type="text\/javascript">    \/\/ \u767e\u5ea6\u5730\u56feAPI\u529f\u80fd    var map = new BMap.Map("allmap");    \/\/ \u521b\u5efaMap\u5b9e\u4f8b    var point = new BMap.Point(114.13429547417234, 22.574919563811855);\/\/\u6807\u6ce8\u70b9    map.centerAndZoom(point, 16);  \/\/ \u521d\u59cb\u5316\u5730\u56fe,\u8bbe\u7f6e\u4e2d\u5fc3\u70b9\u5750\u6807\u548c\u5730\u56fe\u7ea7\u522b    map.addControl(new BMap.MapTypeControl());   \/\/\u6dfb\u52a0\u5730\u56fe\u7c7b\u578b\u63a7\u4ef6    map.setCurrentCity("\u6df1\u5733\u5e02\u6c34\u8d1d\u4e07\u5c71\u73e0\u5b9d\u56ed");          \/\/ \u8bbe\u7f6e\u5730\u56fe\u663e\u793a\u7684\u57ce\u5e02 \u6b64\u9879\u662f\u5fc5\u987b\u8bbe\u7f6e\u7684    map.enableScrollWheelZoom(true);     \/\/\u5f00\u542f\u9f20\u6807\u6eda\u8f6e\u7f29\u653e    map.addControl(new BMap.NavigationControl());\/\/\u5de6\u4e0a\u63a7\u4ef6    \/\/\u6807\u6ce8      var marker = new BMap.Marker(point);        \/\/ \u521b\u5efa\u6807\u6ce8        map.addOverlay(marker);                     \/\/ \u5c06\u6807\u6ce8\u6dfb\u52a0\u5230\u5730\u56fe\u4e2d    \/\/marker.setAnimation(BMAP_ANIMATION_BOUNCE); \/\/\u8df3\u52a8\u7684\u52a8\u753b    \/\/\u76d1\u542c\u6807\u6ce8\u4e8b\u4ef6    marker.addEventListener("click", function(e){         alert("\u5f53\u524d\u4f4d\u7f6e\uff1a" + e.point.lng + ", " + e.point.lat);     });    \/\/\u6258\u62fd\u7684\u6807\u6ce8    marker.enableDragging();        marker.addEventListener("dragend", function(e){         alert("\u5f53\u524d\u4f4d\u7f6e\uff1a" + e.point.lng + ", " + e.point.lat);        })    \/\/\u5730\u56fe\u4e0a\u52a0\u4fe1\u606f\u7a97\u53e3    var opts = {         width : 250,     \/\/ \u4fe1\u606f\u7a97\u53e3\u5bbd\u5ea6         height: 100,     \/\/ \u4fe1\u606f\u7a97\u53e3\u9ad8\u5ea6         title : "\u95ea\u76df\u73e0\u5b9d"  \/\/ \u4fe1\u606f\u7a97\u53e3\u6807\u9898       }        var infoWindow = new BMap.InfoWindow("\u8fd9\u91cc\u662f\u5185\u5bb9\u533a", opts);  \/\/ \u521b\u5efa\u4fe1\u606f\u7a97\u53e3\u5bf9\u8c61        map.openInfoWindow(infoWindow, map.getCenter());      \/\/ \u6253\u5f00\u4fe1\u606f\u7a97\u53e3    \/\/\u5de6\u4e0a\u89d2\u52a0\u6bd4\u4f8b\u5c3a    var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});\/\/ \u5de6\u4e0a\u89d2\uff0c\u6dfb\u52a0\u6bd4\u4f8b\u5c3a    map.addControl(top_left_control);        \/\/ \u6dfb\u52a0\u5e26\u6709\u5b9a\u4f4d\u7684\u5bfc\u822a\u63a7\u4ef6(\u5730\u56fe\u4e0a\u7684\u70b9\u51fb\u83b7\u53d6\u5f53\u524d\u4f4d\u7f6e)      var navigationControl = new BMap.NavigationControl({        \/\/ \u9760\u5de6\u4e0a\u89d2\u4f4d\u7f6e        anchor: BMAP_ANCHOR_TOP_LEFT,        \/\/ LARGE\u7c7b\u578b        type: BMAP_NAVIGATION_CONTROL_LARGE,        \/\/ \u542f\u7528\u663e\u793a\u5b9a\u4f4d        enableGeolocation: true      });      map.addControl(navigationControl);      \/\/ \u6dfb\u52a0\u5b9a\u4f4d\u63a7\u4ef6      var geolocationControl = new BMap.GeolocationControl();      geolocationControl.addEventListener("locationSuccess", function(e){        \/\/ \u5b9a\u4f4d\u6210\u529f\u4e8b\u4ef6        var address = '';        address += e.addressComponent.province;        address += e.addressComponent.city;        address += e.addressComponent.district;        address += e.addressComponent.street;        address += e.addressComponent.streetNumber;        alert("\u5f53\u524d\u5b9a\u4f4d\u5730\u5740\u4e3a\uff1a" + address);      });      geolocationControl.addEventListener("locationError",function(e){        \/\/ \u5b9a\u4f4d\u5931\u8d25\u4e8b\u4ef6        alert(e.message);      });      map.addControl(geolocationControl);          \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\u6dfb\u52a0\u57ce\u5e02\u5217\u8868\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/    \/*var mp = new BMap.Map("allmap");    var point = new BMap.Point(116.404, 39.915);    mp.centerAndZoom(point, 14);    mp.enableScrollWheelZoom();    mp.enableInertialDragging();        mp.enableContinuousZoom();        var size = new BMap.Size(10, 20);    mp.addControl(new BMap.CityListControl({        anchor: BMAP_ANCHOR_TOP_LEFT,        offset: size,        \/\/ \u5207\u6362\u57ce\u5e02\u4e4b\u95f4\u4e8b\u4ef6        \/\/ onChangeBefore: function(){        \/\/    alert('before');        \/\/ },        \/\/ \u5207\u6362\u57ce\u5e02\u4e4b\u540e\u4e8b\u4ef6        \/\/ onChangeAfter:function(){        \/\/   alert('after');        \/\/ }    }));    *\/        \/****************\u6d4b\u8ddd\u79bb***************\/    \/\/ \u767e\u5ea6\u5730\u56feAPI\u529f\u80fd    \/*var map = new BMap.Map("allmap");               map.centerAndZoom("\u4e07\u5c71\u73e0\u5b9d\u56ed",16);                      var myDis = new BMapLib.DistanceTool(map);    map.addEventListener("load",function(){        myDis.open();  \/\/\u5f00\u542f\u9f20\u6807\u6d4b\u8ddd        \/\/myDis.close();  \/\/\u5173\u95ed\u9f20\u6807\u6d4b\u8ddd\u5927    });    *\/<\/script> <\/p>"}