You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

109 lines
3.3 KiB

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
  6. <title>GeolocationControl</title>
  7. <style type="text/css">/*<![CDATA[*/
  8. body{margin:0;padding:0;font-family:Times New Roman, serif}
  9. p{margin:0;padding:0}
  10. html,body{
  11. width:100%;
  12. height:100%;
  13. }
  14. #map_container{height:100%; border: 1px solid #999;height:300px;}
  15. @media print{
  16. #notes{display:none}
  17. #map_container{margin:0}
  18. }
  19. /*]]>*/</style>
  20. <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
  21. <script type="text/javascript" src="http://api.map.baidu.com/library/SearchControl/1.4/src/SearchControl_min.js"></script>
  22. <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchControl/1.4/src/SearchControl_min.css" />
  23. <link href="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.css" rel="stylesheet" type="text/css" />
  24. <script type="text/javascript" src="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.js"></script>
  25. </head>
  26. <body>
  27. <div id="searchBox"></div>
  28. <div id="map_container"></div>
  29. <div id="test_container">
  30. 检索类型
  31. <select id="selectType" name="">
  32. <option value="1">周边检索</option>
  33. <option value="2">公交检索</option>
  34. <option value="3">驾车检索</option>
  35. </select>
  36. </div>
  37. </body>
  38. <script type="text/javascript">/*<![CDATA[*/
  39. // 创建地图对象并初始化
  40. var mp = new BMap.Map("map_container",{
  41. enableHighResolution: true //是否开启高清
  42. });
  43. var point = new BMap.Point(116.404, 39.915);
  44. mp.centerAndZoom(point, 14); //初始化地图
  45. mp.enableInertialDragging(); //开启关系拖拽
  46. mp.enableScrollWheelZoom(); //开启鼠标滚动缩放
  47. // 添加定位控件
  48. var geoCtrl = new BMap.GeolocationControl({
  49. showAddressBar : true //是否显示
  50. , enableAutoLocation : false //首次是否进行自动定位
  51. , offset : new BMap.Size(0,25)
  52. //, locationIcon : icon //定位的icon图标
  53. });
  54. //监听定位成功事件
  55. geoCtrl.addEventListener("locationSuccess",function(e){
  56. console.log(e);
  57. });
  58. //监听定位失败事件
  59. geoCtrl.addEventListener("locationError",function(e){
  60. console.log(e);
  61. });
  62. // 将定位控件添加到地图
  63. mp.addControl(geoCtrl);
  64. //检索类型
  65. var type = "";
  66. type = LOCAL_SEARCH ; //周边检索
  67. //type = TRANSIT_ROUTE; //公交检索
  68. //type = DRIVING_ROUTE; //驾车检索
  69. //创建鱼骨控件
  70. var navCtrl = new BMap.NavigationControl({
  71. anchor: BMAP_ANCHOR_TOP_LEFT //设置鱼骨控件的位置
  72. });
  73. // 将鱼骨添加到地图当中
  74. mp.addControl(navCtrl);
  75. //创建检索控件
  76. var searchControl = new BMapLib.SearchControl({
  77. container : "searchBox" //存放检索控件的容器
  78. , map : mp //检索的关联地图
  79. , type : type //检索类型
  80. });
  81. document.getElementById("selectType").onchange = function () {
  82. searchControl.setType(this.value);
  83. };
  84. //添加路况控件
  85. var ctrl = new BMapLib.TrafficControl({
  86. showPanel: false //是否显示路况提示面板
  87. });
  88. mp.addControl(ctrl);
  89. ctrl.setAnchor(BMAP_ANCHOR_TOP_RIGHT);
  90. /*]]>*/</script>
  91. </html>