2016-07-03 12 views
-1

2点間の方向を見つけるのに役立つ簡単なウェブサイトを作っています。 と私は奇妙な何かを発見した。 map.google.comで検索した場合、正確な結果が返されますが、実際の結果は返されません。 は、たとえば、私が使用して宛先として「ニューヨーク大学、ニューヨーク、NY、米国」原点とし、「260ブロードウェイニューヨークNY 10007」を設定しmap.google.com using map.google.comjavascriptのmap.google.comとgoogle apiの結果が異なる

私が使用して私のウェブサイトを使用する場合GoogleマップAPI-> using api

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDs8SYxRh-pMXa9Qe-K1nVY0g3CLpmJ9mo&signed_in=true&libraries=places&callback=initMap" async defer></script> 
 
function calculateAndDisplayRoute(directionsDisplay, directionsService, 
 
    markerArray, stepDisplay, map) { 
 
    for (var i = 0; i < markerArray.length; i++) { 
 
    markerArray[i].setMap(null); 
 
    } 
 
    directionsDisplay.setPanel(document.getElementById('panel')); 
 

 
    
 

 
    var selectedMode = document.getElementById('mode').value; 
 
    directionsService.route({ 
 
    origin: document.getElementById('pac-input').value, 
 
    destination: document.getElementById('pac-input2').value, 
 
    travelMode: google.maps.TravelMode[selectedMode] 
 
    }, 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); 
 
    } 
 
    }); 
 
} 
 
            

+0

をあなたのアドレスを入力(http://jsfiddle.net/16tf8uzt/)[掲載のコードは私のために、正しい結果を返します]。この問題を示す[最小、完全、テスト済みおよび読み取り可能な例](http://stackoverflow.com/help/mcve)を提供してください。 – geocodezip

答えて

0

あなたは場所のオートコンプリート入力を持っているし、あなたのコード内でこれらの入力の値を読み取るように見えます。

私は、あなたのルートサービスでオートプレースの場所から場所IDを使用することをお勧めします。このようにすれば、選択したアドレスで作業することが確実になります。

この例を見て、そこhttp://jsbin.com/xuyisem/1/edit?html,output

関連する問題