當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS 实现GOOGLE地图线路规划
生活随笔
收集整理的這篇文章主要介紹了
JS 实现GOOGLE地图线路规划
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、準備GOOGLE地圖的KEY
如果不知道申請地址,請點擊 此鏈接?獲取 GOOGLE MAP KEY
2、廢話不多說,開始測試 JS代碼(上海到江蘇路線)
<script language="javascript" type="text/javascript"> function initMap() {var initAddr = {lat: 31.230416, lng: 121.473701};var destAddr = {lat: 32.230416, lng: 120.47370};var map = new google.maps.Map(document.getElementById('map_canvas'), {center: initAddr,scrollwheel: false,zoom: 7});var directionsDisplay = new google.maps.DirectionsRenderer({map: map});// Set destination, origin and travel mode.var request = {origin: initAddr,destination: destAddr,travelMode: google.maps.TravelMode.DRIVING};// Pass the directions request to the directions service.var directionsService = new google.maps.DirectionsService();directionsService.route(request, function(response, status) {if (status == google.maps.DirectionsStatus.OK) {// Display the route on the map.directionsDisplay.setDirections(response);}}); } </script>3、HTML代碼 <body οnlοad="initMap()"> <div id="map_canvas" style="height:90%;top:30px"></div> </body>4、收獲地圖;(如果還有疑問可訪問GOOGLE MAP 官網 GOOGLE MAP API)
總結
以上是生活随笔為你收集整理的JS 实现GOOGLE地图线路规划的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 硬件基础知识---(8)如何选取 电容
- 下一篇: CreateJS