map.html 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>地图单击拾取经纬度</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  8. <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  9. <style>
  10. body,
  11. html,
  12. #container {
  13. overflow: hidden;
  14. width: 100%;
  15. height: 100%;
  16. margin: 0;
  17. font-family: "微软雅黑";
  18. }
  19. .info {
  20. z-index: 999;
  21. width: auto;
  22. min-width: 16rem;
  23. padding: .75rem 1.25rem;
  24. margin-left: 1.25rem;
  25. position: fixed;
  26. top: 1rem;
  27. background-color: #fff;
  28. border-radius: .25rem;
  29. font-size: 14px;
  30. color: #666;
  31. box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
  32. }
  33. </style>
  34. <script src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=94iK6uYDWx7AV4FbrPaQDtRp8uBHWIoA"></script>
  35. </head>
  36. <body>
  37. <div id="container"></div>
  38. <div class = "info">
  39. <input name="content" id="content"> <button onclick="funJs()">检索</button>
  40. <div id="lanlng" style="padding-top: 1rem"></div>
  41. </div>
  42. </body>
  43. </html>
  44. <script>
  45. var map = new BMapGL.Map('container');
  46. map.centerAndZoom(new BMapGL.Point(118.8660, 31.96949), 15);
  47. map.enableScrollWheelZoom(true);
  48. map.addEventListener('click', function (e) {
  49. document.getElementById("lanlng").innerText=e.latlng.lng.toFixed(6) + ',' + e.latlng.lat.toFixed(6);
  50. //alert('点击位置经纬度:' + e.latlng.lng + ',' + e.latlng.lat);
  51. });
  52. function funJs() {
  53. map.clearOverlays();
  54. document.getElementById("lanlng").innerText = "";
  55. var local = new BMapGL.LocalSearch(map, {
  56. renderOptions:{map: map}
  57. });
  58. local.search(document.getElementById("content").value);
  59. }
  60. </script>