1

位置情報と GPS 機能を実現するために、Google マップでコードを書きました。しかし、ナビゲーションルートは常に表示されません。どこが間違っているのかわからないのですか? 助けを求めてください。誰が助けてくれますか? ありがとうございました!

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

1 に答える 1

0

このコードが間違っていることがわかりました

    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); 
于 2012-08-27T01:43:14.827 に答える