2013-10-18 107 views
0

我的腳本有問題,我需要看兩個點之間的方式,函數directionsService.route()返回狀態「OK」,但在地圖中我看不到路線! 代碼:DirectionsMap谷歌地圖的問題API

<script type="text/javascript" > 

    var dirService; 

    var render; 

    function calcolateRoute(){ 

     dirService = new google.maps.DirectionsService(); 


     var myOrigin = new google.maps.LatLng(46.44664,12.381245); 

     var myDestination = new google.maps.LatLng(46.429516,12.373939); 


     var mapOptions = { 

         zoom:15, 

         mapTypeId: google.maps.MapTypeId.ROADMAP, 

         center: myOrigin 

        }; 

     var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 


     var renderOpt = { 

      map:map, 

      origin: myOrigin, 

      destination: myDestination     

      }; 


     render = new google.maps.DirectionsRenderer(renderOpt); 


     render.setMap(map); 


     var requestRoute = { 

      origin: myOrigin, 

      destination: myDestination, 

      travelMode: google.maps.DirectionsTravelMode.DRIVING 

     }; 

     dirService.route(requestRoute, function(result, status){ 

       if(status == google.maps.DirectionsStatus.OK){ 

        render.setDirection(result); 

        alert(status);     

       }else{ 

        alert(status); 


       } 

      }); 

    } 

    google.maps.event.addDomListener(window, 'load', calcolateRoute); 

</script> 

謝謝所有幫助

+0

由@Andy回答:這只是錯誤的setDirections錯誤..檢查此..http://jsfiddle.net/dFjdy/114/ – nik

回答

0

這是下降到一個錯字。改爲嘗試render.setDirections(result);