Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 谷歌地图API出现问题,请求支持_Html_Google Maps - Fatal编程技术网

Html 谷歌地图API出现问题,请求支持

Html 谷歌地图API出现问题,请求支持,html,google-maps,Html,Google Maps,我用谷歌地图写了一段代码来实现定位和GPS功能。 但是导航路线总是显示不出来,我不知道哪里错了? 请求帮助。谁能帮助我? 谢谢大家! javascript代码 <script type="text/javascript"> $( "#map-page" ).live( "pageinit", function() { var directionsDisplay; var directionsService = new google.maps.Direc

我用谷歌地图写了一段代码来实现定位和GPS功能。 但是导航路线总是显示不出来,我不知道哪里错了? 请求帮助。谁能帮助我? 谢谢大家!

javascript代码

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

        directionsDisplay = new google.maps.DirectionsRenderer();  

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

        };  

        map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);  
        directionsDisplay.setMap(map);  
        // 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);//在没有地理位置支持时默认为加利福尼亚州好莱坞
如果(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){
directionsDisplay=new google.maps.DirectionsRenderer();
变量myOptions={
缩放:10,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
};  
map=new google.maps.map(document.getElementById(“地图画布”),myOptions);
方向显示.setMap(地图);
//在当前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
};  
路由(请求、函数(响应、状态){
如果(status==google.maps.directionstatus.OK){
方向显示。设置方向(响应);
}  
});  
}  
});  
我已经锻炼好了 这段代码是错误的

    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        
}   
我指挥

// Location found, show map with these coordinates    
drawMap(defaultLatLng);  
calcRoute(defaultLatLng); 

我希望您有
sensor=true
?注意您的代码--您的注释是--“查找用户当前位置。缓存位置5分钟,6秒后超时”--但您的代码是:navigator.geolocation.getCurrentPosition(成功,失败,{maximumAge:500000,enableHighAccurance:true,超时:6000});有两个问题。500000是8.33分钟,而不是5分钟(500000/1000/60)。但更重要的是,这就是maximumAge的含义。您告诉设备您愿意接受的位置,但告诉它缓存多长时间。