123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
- <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
- <style>
- * {
- margin: 0;
- padding: 0;
- }
- html,
- body,
- #container {
- height: 100%;
- width: 100%;
- }
- .distance {
- background-color: #00000061;
- position: absolute;
- bottom: 20px;
- right: 20px;
- color: white;
- padding: 6px 10px;
- border-radius: 6px;
- }
- </style>
- </head>
- <body>
- <div id="container"></div>
- <div id="distance" class='distance'></div>
- <script
- src="https://webapi.amap.com/maps?v=2.0&key=211dd6f989e719022aaf47ddb0659c47&plugin=AMap.Scale,AMap.ToolBar,AMap.Geocoder,AMap.Geolocation,Geolocation,AMap.Driving">
- </script>
- <script src="https://webapi.amap.com/loca?v=2.0.0&key=211dd6f989e719022aaf47ddb0659c47"></script>
- <script>
- function getQuery(name) {
-
- let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
- let r = window.location.search.substr(1).match(reg);
- console.log(r);
- if (r != null) {
-
- return decodeURIComponent(r[2]);
- }
- return null;
- }
- let starLnglat = getQuery('lat').toString().split(',');
- let endLnglat = getQuery('unsendaddress').toString().split(',')
- console.log(endLnglat,111111111)
-
- console.log('---------------------')
- console.log(starLnglat)
- var map = new AMap.Map('container', {
- zoom: 12,
- center: [starLnglat[1], starLnglat[0]],
- resizeEnable: true
- });
- map.clearMap();
- var startIcon = new AMap.Icon({
- size: new AMap.Size(25, 25),
- image: './img/1.png',
- imageSize: new AMap.Size(25, 25),
- });
-
- var drivingOption = {
- policy: AMap.DrivingPolicy
- .LEAST_TIME,
- ferry: 1,
- map: map,
- hideMarkers: false,
- autoFitView: true
- }
-
- var dis = '距离'+getQuery('distance')+'公里'
- document.getElementById("distance").innerHTML = dis
-
- render(endLnglat[1], endLnglat[0])
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function render(endLng, endLat) {
-
- var driving = new AMap.Driving(drivingOption)
-
- driving.search(new AMap.LngLat(starLnglat[1], starLnglat[0]), new AMap.LngLat(endLng, endLat), function(status,
- result) {
- if (status === 'complete') {
- console.log('绘制驾车路线完成')
- } else {
- console.log('获取驾车数据失败:' + result)
- }
- });
-
-
-
-
-
-
-
- var capitals = [];
- var facilities = [];
- for (var i = 0; i < capitals.length; i++) {
- var marker = new AMap.Marker({
- position: new AMap.LngLat(capitals[i].center[0], capitals[i].center[1]),
- offset: new AMap.Pixel(-10, -10),
- icon: startIcon,
- });
- facilities.push(marker);
- }
- map.add(facilities);
- }
-
- function clickHandler(e) {
- map.clearMap();
- var endLng = e.lnglat.getLng();
- var endLat = e.lnglat.getLat();
- render(endLng, endLat)
- }
- </script>
- <script>
- </script>
- </body>
- </html>
|