方向API谷歌方向请求失败,因为没有找到
Direction API google - direction request failed due to not found
我试图显示两点之间的距离。但我面临这个错误方向请求失败,由于没有找到。我谷歌了一下,但没有找到解决办法。请看看我的代码,告诉我,如果我做错了什么。
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 side:
<input id="start" class="controls" type="text"
placeholder="picup lock">
<input id="end" class="controls" type="text"
placeholder="drop off">
根据此文档,错误NOT_FOUND表示请求的起源,目的地或路径点中指定的至少一个位置无法被地理编码。
确保point1和point3不是空的。API不知道如何创建从"到"的路由。
查看相关的票证和教程
我昨天有同样的问题,通过c# httpClient使用API。但同样的请求在浏览器中运行良好。经过一些调试,我发现它只工作,如果我在httpClient发送Accept-Language头…
相关文章:
- ng映射方向备选方案
- RubyonRails——构建交互式接口应该朝哪个方向发展
- 需要帮助谷歌地图方向面板在FancyBox中显示
- onclick函数需要双击,因为类分配延迟
- 在D3.js中,有没有任何方法可以将x和y方向上的滚动事件绑定到平移svg
- 在ES6中,模块将导致多个网络调用,因为两个模块不能在单个文件中定义
- 我怎样才能知道用户滑动的方向
- 如何获得Bootstrap Datepicker的年和月,因为它在变化
- ACE编辑器正在删除模块,因为define是't一根绳子
- 未能加载,因为找不到支持的源.当播放HTML5音频元素时
- 任何人都知道IE7设置或更新/补丁,它可以防止IE因为jquery错误而无法加载页面
- "未捕获类型错误/丢弃意外“;因为一句台词而出现?(HTML w/<脚本>)
- CKeditor预览插件.js,为Chrome和IE进行编辑.因为它拒绝CSS样式
- 使用谷歌地图API和phonegap显示当前位置+方向
- 用真或假初始化变量是否在 Javascript 中建立了内容的方向
- 带有自定义标记的谷歌地图方向APIv3
- 在角度方向的元素之前插入
- 更改D3方向力图中箭头标记的方向
- fullpage.js在滚动时更改滚动方向
- 方向API谷歌方向请求失败,因为没有找到