0
我想知道如何從路線請求的原點檢索路線計算出來的latlng。 我想用它來繪製一條圍繞已經制作的路線的原點的圓圈。谷歌地圖API - 從方向的原點檢索latlng?
function calcRoute() {
start = document.getElementById("start").value; //value from start textbox
end = document.getElementById("end").value; //value from end textbox
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(result, status) {
//if route can be generated
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
//circle.setCenter();
}else{
//display window alert with status error
window.alert('Directions request failed due to ' + status);
}
});
}
被用於始發地和目的地使用自動完成方法由谷歌開發網頁,其中是返回所有類型的位置我INITIALISE函數內部文本框。
//autocomplete section
var inputStart = document.getElementById('start');
var optionsStart = {}; //Empty which will return all types
autocomplete = new google.maps.places.Autocomplete(inputStart, optionsStart);
var inputEnd = document.getElementById('end');
var optionsEnd = {}; //Empty which will return all types
autocomplete = new google.maps.places.Autocomplete(inputEnd, optionsEnd);
//--------------------------------------------------
香港專業教育學院研究一下,我需要剛剛返回地址,然後使用地址解析器中檢索我想要的數據,或者可以在此與我的代碼是現在的方式來完成。
我已經看過這段代碼,但不知道如何實現它,如果這也有幫助。
result.routes[0].legs[0].start_location;
啊謝謝,我想我試着將latlng聲明爲一個變量,並將該變量輸入到setCenter參數中,但沒有工作。謝謝!現在我只需要能夠用某種滑塊編輯raidius,有時間進行更多的研究哈哈。再次感謝。 – aa29
歡迎。但是,如果你執行'var xxx = result.routes [0] .legs [0] .start_location'並在'setCenter()'中使用該變量,沒有理由不起作用......但是你必須使用**內**請求功能。 – MrUpsidown