0

我的脚本有问题,我需要查看两点之间的路径,函数方向服务.route() 返回状态“OK”但在地图中我看不到路线!编码:

 <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>

谢谢大家的帮助

4

1 回答 1

0

这归结为一个错字。试试render.setDirections(result);吧。

于 2013-10-18T10:45:18.177 回答