0

2点間の距離を表示しようとしています。しかし、私はこのエラーに直面しています方向の要求が見つかりませんでしたので、が見つかりませんでした。私はグーグルでは解決策が見つかりませんでした。私のコードを見て、私が何か間違っているかどうか教えてください。方向API google - 方向の要求が見つかりませんでした。

function initAutocomplete() { 

    var markerArray = []; 

    // Instantiate a directions service. 
    var directionsService = new google.maps.DirectionsService; 

    // Create a map and center it on Manhattan. 
    var map = new google.maps.Map(document.getElementById('map-canvas'), { 
     zoom: 13, 
     center: {lat: 40.771, lng: -73.974} 
    }); 

    // Create a renderer for directions and bind it to the map. 
    var directionsDisplay = new google.maps.DirectionsRenderer({map: map}); 

    // Instantiate an info window to hold step text. 
    var stepDisplay = new google.maps.InfoWindow; 

    // Display the route between the initial start and end selections. 
    calculateAndDisplayRoute(
     directionsDisplay, directionsService, markerArray, stepDisplay, map); 

    // Listen to change events from the start and end lists. 
    var onChangeHandler = function() { 
     calculateAndDisplayRoute(
      directionsDisplay, directionsService, markerArray, stepDisplay, map); 
    }; 
    document.getElementById('start').addEventListener('change', onChangeHandler); 
    document.getElementById('end').addEventListener('change', onChangeHandler); 
    } 

    function calculateAndDisplayRoute(directionsDisplay, directionsService, 
     markerArray, stepDisplay, map) { 
    // First, remove any existing markers from the map. 
    for (var i = 0; i < markerArray.length; i++) { 
     markerArray[i].setMap(null); 
    } 

    // Retrieve the start and end locations and create a DirectionsRequest using 
    // WALKING directions. 
    directionsService.route({ 
     origin: document.getElementById('start').value, 
     destination: document.getElementById('end').value, 
     travelMode: google.maps.TravelMode.WALKING 
    }, function(response, status) { 
     // Route the directions and pass the response to a function to create 
     // markers for each step. 
     if (status === google.maps.DirectionsStatus.OK) { 
     document.getElementById('warnings-panel').innerHTML = 
      '<b>' + response.routes[0].warnings + '</b>'; 
     directionsDisplay.setDirections(response); 
     showSteps(response, markerArray, stepDisplay, map); 
     } else { 
     window.alert('Directions request failed due to ' + status); 
     } 
    }); 
    } 

    function showSteps(directionResult, markerArray, stepDisplay, map) { 
    // For each step, place a marker, and add the text to the marker's infowindow. 
    // Also attach the marker to an array so we can keep track of it and remove it 
    // when calculating new routes. 
    var myRoute = directionResult.routes[0].legs[0]; 
    for (var i = 0; i < myRoute.steps.length; i++) { 
     var marker = markerArray[i] = markerArray[i] || new google.maps.Marker; 
     marker.setMap(map); 
     marker.setPosition(myRoute.steps[i].start_location); 
     attachInstructionText(
      stepDisplay, marker, myRoute.steps[i].instructions, map); 
    } 
    } 

    function attachInstructionText(stepDisplay, marker, text, map) { 
    google.maps.event.addListener(marker, 'click', function() { 
     // Open an info window when the marker is clicked on, containing the text 
     // of the step. 
     stepDisplay.setContent(text); 
     stepDisplay.open(map, marker); 
    }); 
    } 

のHTML側:

<input id="start" class="controls" type="text" 
    placeholder="picup lock"> 

    <input id="end" class="controls" type="text" 
    placeholder="drop off"> 
+0

'ZERO_RESULTS'を取得したときに使用している開始値と終了値は何ですか?エラーを示す[最小、完全、テスト済みおよび読み取り可能な例](http://stackoverflow.com/help/mcve)を入力してください。 – geocodezip

+0

あなたは実際に非推奨の[google-maps-api-2](http://stackoverflow.com/tags/google-maps-api-2/info)を使用していますか? – geocodezip

+0

いいえ、その機能が無効になっていて、正常に動作しています – Devilism

答えて

0

このdocumentationから基づき、エラーNOT_FOUND要求の起点、宛先に指定された場所の少なくともいずれかを示し、またはウェイポイントをジオコーディングすることができませんでした。

point1とpoint3が空でないことを確認してください。 APIは ""から ""への経路を作成する方法を知らない。

これを確認してください。ticketおよびtutorial

関連する問題