Html 为什么赢了';谷歌地图在我的网页上导航吗?

Html 为什么赢了';谷歌地图在我的网页上导航吗?,html,google-maps,navigation,Html,Google Maps,Navigation,我想使用地理定位来定位用户的位置,然后在用户之间导航;它的位置和一个固定点,但谷歌地图只是不会导航,我使用的代码从谷歌的官方文档 怎么了?我试了几千次都快疯了,请帮忙 <script type="text/javascript"> $( "#map-page" ).live( "pageinit", function() { var directionsDisplay; var directionsService = new goog

我想使用地理定位来定位用户的位置,然后在用户之间导航;它的位置和一个固定点,但谷歌地图只是不会导航,我使用的代码从谷歌的官方文档

怎么了?我试了几千次都快疯了,请帮忙

   <script type="text/javascript">

    $( "#map-page" ).live( "pageinit", function() {

        var directionsDisplay;
        var directionsService = new google.maps.DirectionsService();
        var map;
        var salon = new google.maps.LatLng(22.981666,120.194301);
        var defaultLatLng = new google.maps.LatLng(22.983587,120.22599);  // Default to Hollywood, CA when no geolocation support

        if ( navigator.geolocation ) {
            function success(pos) {
                // Location found, show map with these coordinates
                drawMap(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
                calcRoute(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));

            }

            function fail(error) {
                console.log(error);
                drawMap(defaultLatLng);  // Failed to find location, show default map
            }

            // Find the users current position.  Cache the location for 5 minutes, timeout after 6 seconds
            navigator.geolocation.getCurrentPosition(success, fail, {maximumAge: 500000, enableHighAccuracy:true, timeout: 6000});
        } else {
            drawMap(defaultLatLng);  // No geolocation support, show default map    
        }

        function drawMap(latlng) {
            var myOptions = {
                zoom: 10,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP

            };

            var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);

            // Add an overlay to the map of current lat/lng
            var marker = new google.maps.Marker({
                position: latlng,
                map: map,
                title: "Greetings!"
            });

            var marker = new google.maps.Marker({
                position:new google.maps.LatLng(22.981666,120.194301),
                map:map,
                title:"the salon"
            });
        }

        function calcRoute(latlng) {
        var start = latlng;
        var end = new google.maps.LatLng(22.981666,120.194301);
        var request = {
            origin:start,
            destination:end,
            travelMode: google.maps.TravelMode.DRIVING
        };
        directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
        }
      });
    }


    });


        </script>

$(“#映射页”).live(“pageinit”,function(){
var方向显示;
var directionsService=new google.maps.directionsService();
var映射;
var salon=new google.maps.LatLng(22.981666120.194301);
var defaultLatLng=new google.maps.LatLng(22.983587120.22599);//在没有地理位置支持时默认为加利福尼亚州好莱坞
if(navigator.geolocation){
功能成功(pos){
//找到位置,用这些坐标显示地图
drawMap(新的google.maps.LatLng(pos.coords.lation,pos.coords.longitude));
calcRoute(新的google.maps.LatLng(pos.coords.lation,pos.coords.longitude));
}
功能失败(错误){
console.log(错误);
drawMap(defaultLatLng);//找不到位置,显示默认地图
}
//查找用户当前位置。缓存该位置5分钟,6秒后超时
navigator.geolocation.getCurrentPosition(成功,失败,{maximumAge:500000,enableHighAccurance:true,超时:6000});
}否则{
drawMap(defaultLatLng);//不支持地理位置,显示默认地图
}
功能绘图图(latlng){
变量myOptions={
缩放:10,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“地图画布”),myOptions);
//在当前lat/lng地图上添加覆盖图
var marker=new google.maps.marker({
位置:latlng,
地图:地图,
标题:“你好!”
});
var marker=new google.maps.marker({
位置:新google.maps.LatLng(22.981666120.194301),
地图:地图,
标题:“沙龙”
});
}
功能计算器(latlng){
var启动=latlng;
var end=new google.maps.LatLng(22.981666120.194301);
var请求={
来源:start,
目的地:完,
travelMode:google.maps.travelMode.DRIVING
};
路由(请求、功能(响应、状态){
if(status==google.maps.directionstatus.OK){
方向显示。设置方向(响应);
}
});
}
});

您忘记设置
方向显示

但我设置了方向显示。设置方向(响应);here@oratis:因此,这不是为了让他人为您编写代码。还有其他一些网站可以做到这一点,例如“雇佣一个编码员”:你调用了一个方法setDirections(),但它没有定义。不,也许你可以检查已经定义的代码。我只需要检查你的代码,而在那里它没有定义。