我将项目从使用bing maps v7 ajax api升级到使用v8 api。我遇到了一个问题,我收到的消息说“#34;你输入的航路点无法找到。"所以我备份并修改了一个示例屏幕来做我正在做的事情并且工作正常。所以我把它(用fiddler)缩小到为每个航点做出的REST调用,得到一个错误,说第一种情况下userMapView超出范围但在第二种情况下工作正常。我不确定为什么示例代码与我的实际应用程序可能有所不同。这是两个网址。第一个是失败的:
如果我将第一个URL的userMapView参数替换为第二个URL的userMapView参数,则第一个URL也可以。很明显," -180"学位部分不正确,但我不知道它是如何到达那里的。
BTW,这两个URL都是使用我的开发密钥生成的。感谢您的帮助!
编辑: 这是遇到麻烦的大部分代码。在此之前,我已经有了新的地图。此代码是Directions模块的loadModule的回调。虽然我从表单中插入了起源和目的地,但代码有点复杂。另请注意,并非如此区别,userAddress作为true传递给此函数。
function createDrivingRoute(useAddress) {
directionsManager = new Microsoft.Maps.Directions.DirectionsManager(bmap);
locs = [];
var fromWayPoint;
fromWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: fromAddressSearch });
locs.push(fromWayPoint);
directionsManager.addWaypoint(fromWayPoint);
if (toLocationArray != null) {
if (toLocationArray.length == 1) {
if (toLocationArray[0] == false) {
toLocationArray = [];
}
}
}
if (useAddress) {
if (toLocationArray != null) {
for (i = 0; i < toLocationArray.length; i++) {
//var toWayPointLoc = new Microsoft.Maps.Directions.Waypoint({ location: toLocationArray[i] });
var toWayPointLoc = new Microsoft.Maps.Directions.Waypoint({ address: toLocationArray[i] });
locs.push(toWayPointLoc);
directionsManager.addWaypoint(toWayPointLoc);
}
for (i = 0; i < toAddressArray.length; i++) {
var toWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: toAddressArray[i] });
locs.push(toWayPoint);
directionsManager.addWaypoint(toWayPoint);
}
} else {
for (i = 0; i < toAddressArray.length; i++) {
var toWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: toAddressArray[i] });
locs.push(toWayPoint);
directionsManager.addWaypoint(toWayPoint);
}
}
} else {
if (toLocationArray != null) {
for (i = 0; i < toLocationArray.length; i++) {
//var toWayPointLoc = new Microsoft.Maps.Directions.Waypoint({ location: toLocationArray[i] });
var toWayPointLoc = new Microsoft.Maps.Directions.Waypoint({ address: toLocationArray[i] });
locs.push(toWayPointLoc);
directionsManager.addWaypoint(toWayPointLoc);
}
}
for (i = 0; i < toAddressArray.length; i++) {
var toWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: toAddressArray[i] });
locs.push(toWayPoint);
directionsManager.addWaypoint(toWayPoint);
}
}
if ($get("<%= chkReturnOrigin.ClientID %>").checked) {
var returnWayPoint = new Microsoft.Maps.Directions.Waypoint({ address: fromAddressSearch });
directionsManager.addWaypoint(fromWayPoint);
}
// Set the element in which the itinerary will be rendered
directionsManager.setRenderOptions({ itineraryContainer: '#directions' });
// Specify a handler for when the directions are calculated
if (directionsUpdatedEventObj) {
Microsoft.Maps.Events.removeHandler(directionsUpdatedEventObj);
directionsUpdatedEventObj = null;
}
directionsUpdatedEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', onDirectionsDisplayedEvent);
if (directionsErrorEventObj) {
Microsoft.Maps.Events.removeHandler(directionsErrorEventObj);
directionsErrorEventObj = null;
}
directionsErrorEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', onDirectionsErrorEvent);
loadedRoute = null;
loadedSteps = [];
directionsManager.calculateDirections();
var destAddress = $get("<%= DestAddressList.ClientID %>").value;
if (destAddress == null || destAddress == "") {
document.getElementById("DistTotal").innerHTML = '';
}
}
答案 0 :(得分:2)
Haven以前没见过这个问题,很奇怪。看看您的代码,如果您使用搜索模块进行地理编码,请不要设置边界选项,看看它是否能解决问题。 bounds属性用于设置REST请求的userMapView属性。如果可行,那么传入的LocationRect对象可能存在问题,或搜索模块如何使用它。我将查看源代码,看看是否存在可能导致此问题的错误。
更新1 :现在我看到您的修改并看到您正在使用路线管理器,我能够看到自动从地图添加了userMapView。不知道为什么它会添加这样不正确的值。看起来他们两次添加相同的坐标而不是添加西北和东南坐标。将看看我是否可以通过挖掘代码来验证这一点。
更新2 :我在代码中发现了错误。我已经将其与开发团队一起记录下来,以便他们可以在下次触摸搜索管理器的代码时解决它。问题是西值被添加到userMapView请求两次,但没有添加东值。
更新3 :好消息,此错误现已在Bing Maps的实验分支中得到解决。您可以通过添加&#34;&amp; branch = experimental&#34;来尝试这一点。到地图脚本URL。这将在计划于2月份进行的下一次定期更新中添加到发布分支。