2016-07-03 1 views
-1

2 포인트 간의 방향을 찾는 데 도움이되는 간단한 웹 사이트를 만들고 있습니다. 그리고 이상한 것을 발견했습니다. map.google.com을 통해 검색하면 정확한 결과를 반환하지만 광산은 그렇지 않습니다. 예를 들어, 내가 사용 대상으로 "뉴욕 대학, 뉴욕, 뉴욕, 미국"원점으로와 "260 브로드 웨이 뉴욕 NY 10007"로 설정 map.google.com using map.google.comjavascript에 대한 map.google.com과 google api의 결과가 다릅니다

내가 사용하여 내 웹 사이트를 사용하는 경우 당신이 장소 자동 완성 입력을 가지고 코드에서 이러한 입력 값을 읽어처럼 GoogleMap으로 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

관련 문제