12th week blog

BaiDu map

 

 1 <html>
 2 
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5     <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
 6     <style type="text/css">
 7         body,
 8         html,
 9         #allmap {
10             width: 100%;
11             height: 100%;
12             overflow: hidden;
13             margin: 0;
14             font-family: "微软雅黑";
15         }
16     </style>
17     <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=9dcpmOco3T9LsWA84dxt99AicXApGgWp"></script>
18     <title>浏览器定位</title>
19 </head>
20 
21 <body>
22     <div id="allmap"></div>
23 </body>
24 
25 </html>
26 <script type="text/javascript">
27     // 百度地图API功能
28     var map = new BMap.Map("allmap");
29     var point = new BMap.Point(104.06792346, 30.67994285);
30     map.centerAndZoom(point, 12);
31 
32     var geolocation = new BMap.Geolocation();
33     geolocation.getCurrentPosition(function(r) {
34         if (this.getStatus() == BMAP_STATUS_SUCCESS) {
35             var mk = new BMap.Marker(r.point);
36             map.addOverlay(mk);
37             map.panTo(r.point);
38             alert('您的位置:' + r.point.lng + ',' + r.point.lat);
39         } else {
40             alert('failed' + this.getStatus());
41         }
42     }, {
43         enableHighAccuracy: true
44     })
45 </script>

 

posted @ 2018-11-22 14:14  hayaahan  阅读(95)  评论(0编辑  收藏  举报