百度地图

废话不多说,直接看代码:

HTML:

[html]  view plain  copy
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />  
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  6. <title>百度地图</title>  
  7. <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>  
  8. <script type="text/javascript">  
  9.         function load() {  
  10.             var map = new BMap.Map("container");  
  11.             var point = new BMap.Point(113.67312,34.758085); //默认中心点  
  12.             var marker = new BMap.Marker(point);  
  13.             var opts = {  
  14.                 width: 250,     // 信息窗口宽度    
  15.                 height: 100,     // 信息窗口高度    
  16.                 //title: "信息窗口标题"  // 信息窗口标题    
  17.             }  
  18.               
  19.             // 创建窗口信息对象。  
  20.             //var infoWindow = new BMap.InfoWindow("这里显示提示信息", opts);  
  21.   
  22.   
  23.             marker.enableDragging(); //启用拖拽  
  24.             marker.addEventListener("dragend", function (e) {  
  25.                 point = new BMap.Point(e.point.lng, e.point.lat); //标记坐标(拖拽以后的坐标)  
  26.                 marker = new BMap.Marker(point);  
  27.   
  28.                 document.getElementByIdx_x("lng").value = e.point.lng;  
  29.                 document.getElementByIdx_x("lat").value = e.point.lat;  
  30.                 infoWindow = new BMap.InfoWindow("当前位置<br />经度:" + e.point.lng + "<br />纬度:" + e.point.lat, opts);  
  31.   
  32.                 map.openInfoWindow(infoWindow, point);  
  33.             })  
  34.   
  35.             map.addControl(new BMap.NavigationControl()); //左上角控件  
  36.             map.enableScrollWheelZoom(); //滚动放大  
  37.             map.enableKeyboard(); //键盘放大  
  38.   
  39.             map.centerAndZoom(point, 13); //绘制地图  
  40.             map.addOverlay(marker); //标记地图  
  41.   
  42.             // 打开信息窗口,infoWindow是创建窗口信息对象的信息  
  43.             //map.openInfoWindow(infoWindow, map.getCenter());  
  44.               
  45.             // 打开信息窗口  
  46.             map.openInfoWindow(map.getCenter());  
  47.         }  
  48.            
  49. </script>  
  50. <style type="text/css">  
  51.     html{height: 100%;}  
  52.     body{height: 50%;margin: 0px;padding: 0px;}  
  53.     #container{width:550px;height: 460px;}  
  54. </style>  
  55. </head>  
  56. <body onload="load()">  
  57.     <div id="container"></div>  
  58. </body>  
  59. </html>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值