本文介绍了他们示例的谷歌地图行车路线源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌举了个例子http://googlemapsapi.blogspot.com/2007/05/driving-directions-support- added-to.html

是否可以在某处找到源代码或有关该精确示例的教程?

解决方案

这是一个使用 v3 API:

<头><meta http-equiv="content-type" content="text/html; charset=UTF-8"/><title>Google Maps API v3 路线示例</title><脚本类型=文本/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script><body style="font-family: Arial; font-size: 12px;"><div style="width: 600px;"><div id="map" style="width: 280px; height: 400px; float: left;"></div><div id="panel" style="width: 300px; float: right;"></div>

<script type="text/javascript">var directionService = new google.maps.DirectionsService();var directionDisplay = new google.maps.DirectionsRenderer();var map = new google.maps.Map(document.getElementById('map'), {变焦:7,mapTypeId: google.maps.MapTypeId.ROADMAP});DirectionsDisplay.setMap(地图);DirectionsDisplay.setPanel(document.getElementById('panel'));无功请求 = {产地:'芝加哥',目的地:纽约",旅行模式:google.maps.DirectionsTravelMode.DRIVING};路线Service.route(请求,功能(响应,状态){如果(状态 == google.maps.DirectionsStatus.OK){DirectionsDisplay.setDirections(响应);}});</html>

截图:

Google gave an examplehttp://googlemapsapi.blogspot.com/2007/05/driving-directions-support-added-to.html

Is the source code available somewhere or a tutorial on that precise example ?

解决方案

Here's a very basic example using the v3 API:

<!DOCTYPE html>
    <html>
    <head>
       <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
       <title>Google Maps API v3 Directions Example</title>
       <script type="text/javascript"
               src="http://maps.google.com/maps/api/js?sensor=false"></script>
    </head>
    <body style="font-family: Arial; font-size: 12px;">
       <div style="width: 600px;">
         <div id="map" style="width: 280px; height: 400px; float: left;"></div>
         <div id="panel" style="width: 300px; float: right;"></div>
       </div>

       <script type="text/javascript">

         var directionsService = new google.maps.DirectionsService();
         var directionsDisplay = new google.maps.DirectionsRenderer();

         var map = new google.maps.Map(document.getElementById('map'), {
           zoom:7,
           mapTypeId: google.maps.MapTypeId.ROADMAP
         });

         directionsDisplay.setMap(map);
         directionsDisplay.setPanel(document.getElementById('panel'));

         var request = {
           origin: 'Chicago',
           destination: 'New York',
           travelMode: google.maps.DirectionsTravelMode.DRIVING
         };

         directionsService.route(request, function(response, status) {
           if (status == google.maps.DirectionsStatus.OK) {
             directionsDisplay.setDirections(response);
           }
         });
       </script>
    </body>
    </html>

Screenshot:

这篇关于他们示例的谷歌地图行车路线源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:24