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.
 
 
 
 
 

39 lines
1.3 KiB

  1. <!DOCTYPE html>
  2. <html lang="zh-cn">
  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. <style type="text/css">
  8. *{
  9. height: 100%; //设置高度,不然会显示不出来
  10. }
  11. </style>
  12. <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  13. <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=lbnOVuOdm1XmZLkI38UKuvSw3DyHUltq"></script>
  14. <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
  15. <script>
  16. $(function(){
  17. navigator.geolocation.getCurrentPosition(translatePoint); //定位
  18. });
  19. function translatePoint(position){
  20. var currentLat = position.coords.latitude;
  21. var currentLon = position.coords.longitude;
  22. var gpsPoint = new BMap.Point(currentLon, currentLat);
  23. BMap.Convertor.translate(gpsPoint, 0, initMap); //转换坐标
  24. }
  25. function initMap(point){
  26. //初始化地图
  27. map = new BMap.Map("map");
  28. map.addControl(new BMap.NavigationControl());
  29. map.addControl(new BMap.ScaleControl());
  30. map.addControl(new BMap.OverviewMapControl());
  31. map.centerAndZoom(point, 15);
  32. map.addOverlay(new BMap.Marker(point))
  33. }
  34. </script>
  35. </head>
  36. <body>
  37. <div id="map"></div>
  38. </body>
  39. </html>