必应地图方向管理器在directionsUpdated事件上引发错误。
当我尝试使用已知的源地址和目标地址纬度&长地址绘制路线时,它不会在地图上绘制路线,而只是显示源地址和目标图标并引发以下错误。
错误:我们找不到一个或多个航点之间的路线。
响应码:1
下面是LoadDirection方法代码。
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', (e) => {
this.directionsManager = new Microsoft.Maps.Directions.DirectionsManager(this.detailMap);
this.directionsManager.clearAll();
// Set Route Mode to driving
this.directionsManager.setRequestOptions({
routeMode: Microsoft.Maps.Directions.RouteMode.driving,
routeDraggable: false
});
this.directionsManager.setRenderOptions({
drivingPolylineOptions: {
strokeThickness: 3
}
});
this.directionsManager.setRenderOptions({
firstWaypointPushpinOptions: { visible: false },
lastWaypointPushpinOptions: { visible: false },
waypointPushpinOptions: { visible: false }
});
const waypoint1 = new Microsoft.Maps.Directions.Waypoint({
address: '2115 Beall St, Houston, TX 77008, US',
location: new Microsoft.Maps.Location(29.8052803, -95.4181495), icon: ''
});
const waypoint2 = new Microsoft.Maps.Directions.Waypoint({
address: '4231 Brightwood Dr, Houston, TX 77068, US',
location: new Microsoft.Maps.Location(30.00005, -95.50392)
});
this.directionsManager.addWaypoint(waypoint1);
this.directionsManager.addWaypoint(waypoint2);
// Add event handler to directions manager.
Microsoft.Maps.Events.addHandler(this.directionsManager, 'directionsUpdated', function (e) {
console.log(e);
this.detailPathLayer.clear();
const routeIndex = e.route[0].routeLegs[0].originalRouteIndex;
const nextLocation = e.route[0].routePath[routeIndex + 1];
const pinLocation = pin.getLocation();
const nextCoord = this.CalculateNextCoord(pinLocation, nextLocation);
});
Microsoft.Maps.Events.addHandler(this.directionsManager, 'directionsError', function (e) {
console.log('Error: ' + e.message + '\r\nResponse Code: ' + e.responseCode);
});
this.directionsManager.calculateDirections();
});
答案 0 :(得分:0)
在您提供的两个位置之间寻找路线应该没有任何问题。下面的独立代码可以正常工作,并且在控制台上打印了DirectionsUpdated事件arg(请注意,您已经将航点图钉设置为通过渲染选项不可见):
var map = new Microsoft.Maps.Map(<CREATE_YOUR_MAP>);
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', (e) => {
this.directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
this.directionsManager.clearAll();
// Set Route Mode to driving
this.directionsManager.setRequestOptions({
routeMode: Microsoft.Maps.Directions.RouteMode.driving,
routeDraggable: false
});
this.directionsManager.setRenderOptions({
drivingPolylineOptions: { strokeThickness: 3 },
firstWaypointPushpinOptions: { visible: false },
lastWaypointPushpinOptions: { visible: false },
waypointPushpinOptions: { visible: false }
});
const waypoint1 = new Microsoft.Maps.Directions.Waypoint({
address: '2115 Beall St, Houston, TX 77008, US',
location: new Microsoft.Maps.Location(29.8052803, -95.4181495), icon: ''
});
const waypoint2 = new Microsoft.Maps.Directions.Waypoint({
address: '4231 Brightwood Dr, Houston, TX 77068, US',
location: new Microsoft.Maps.Location(30.00005, -95.50392)
});
this.directionsManager.addWaypoint(waypoint1);
this.directionsManager.addWaypoint(waypoint2);
Microsoft.Maps.Events.addHandler(this.directionsManager, 'directionsUpdated', function (e) {
console.log(e);
});
Microsoft.Maps.Events.addHandler(this.directionsManager, 'directionsError', function (e) {
console.log('Error: ' + e.message + '\r\nResponse Code: ' + e.responseCode);
});
this.directionsManager.calculateDirections();
});
您可以检查这两个位置之间是否确实引发了错误吗?一切都发生在DirectionsUpdated处理程序中吗? (例如CalculateNextCoord?)