test.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  7. <title>位置经纬度 + 步行路线规划</title>
  8. <style type="text/css">
  9. html,
  10. body,
  11. #container {
  12. width: 100%;
  13. height: 100%;
  14. }
  15. #panel {
  16. position: fixed;
  17. background-color: white;
  18. max-height: 90%;
  19. overflow-y: auto;
  20. top: 10px;
  21. right: 10px;
  22. width: 280px;
  23. }
  24. #panel .amap-call {
  25. background-color: #009cf9;
  26. border-top-left-radius: 4px;
  27. border-top-right-radius: 4px;
  28. }
  29. #panel .amap-lib-walking {
  30. border-bottom-left-radius: 4px;
  31. border-bottom-right-radius: 4px;
  32. overflow: hidden;
  33. }
  34. </style>
  35. <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
  36. <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=116471cff4206df879cc353c2b63c91e&plugin=AMap.Walking"></script>
  37. <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
  38. <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
  39. </head>
  40. <body>
  41. <div id="container"></div>
  42. <div id="panel"></div>
  43. <script type="text/javascript">
  44. var map = new AMap.Map("container", {
  45. resizeEnable: true,
  46. center: [116.397428, 39.90923],//地图中心点
  47. zoom: 13 //地图显示的缩放级别
  48. });
  49. //步行导航
  50. var walking = new AMap.Walking({
  51. map: map,
  52. panel: "panel"
  53. });
  54. //根据起终点坐标规划步行路线
  55. walking.search([116.399028, 39.845042], [116.436281, 39.880719], function(status, result) {
  56. // result即是对应的步行路线数据信息,相关数据结构文档请参考 https://lbs.amap.com/api/javascript-api/reference/route-search#m_WalkingResult
  57. if (status === 'complete') {
  58. log.success('绘制步行路线完成')
  59. } else {
  60. log.error('步行路线数据查询失败' + result)
  61. }
  62. });
  63. var t1=new Array();
  64. AMap.event.addListener(walking,'complete',function (v) {
  65. v.routes[0].steps.forEach(function (v1,k) {
  66. v1.path.forEach(function (v2,k1) {
  67. console.log([v2.lng,v2.lat]);
  68. })
  69. });
  70. })
  71. // console.log(t1);
  72. </script>
  73. </body>
  74. </html>