bing地图从v7升级到v8错误与userMapView
我正在升级项目从使用bing地图v7 ajax api到使用v8 api。我遇到了一个问题,我收到一条消息,指出“您输入的航点无法找到。”所以我备份并修改了一个示例屏幕来做我正在做的事情,并且它工作正常。所以我把它缩小了(用小提琴)到REST调用,这是为每个航点提供的错误,说第一种情况userMapView超出范围,但在第二种情况下正常工作。我不确定为什么这可能会在示例代码与我的实际应用程序中有所不同。以下是两个网址。第一个是失败的一个:bing地图从v7升级到v8错误与userMapView
如果我更换与第二的第一URL的参数userMapView,第一URL也工作。似乎很明显,“-180”度的部分是不正确的,但我不知道它是如何到达那里的。
顺便说一句,这两个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 = '';
}
}
以前没见过这个问题,很奇怪。看看你的代码,如果你使用搜索模块来做地理编码,不要设置边界选项,看看它是否能解决问题。 bounds属性用于设置REST请求的userMapView属性。如果这有效,那么传递LocationRect对象可能存在问题,或者搜索模块如何使用它。我会看看源代码,看看是否有可能导致此问题的错误。
更新1:现在,我看到您的编辑并看到您正在使用路线管理器,我可以看到userMapView自动从地图添加。不知道为什么它会添加这样不正确的值。看起来他们正在添加相同的坐标两次,而不是添加西北和东南坐标。将看看我是否可以通过挖掘代码来验证这一点。
更新2:我找到了代码中的错误。我已经与开发团队记录了这一点,以便他们在下一次触摸搜索管理器的代码时解决它。问题是west值被添加到userMapView请求两次,但没有添加东值。
更新3:好消息,此错误现已在Bing地图的实验分支中解决。您可以通过在地图脚本URL中添加“& branch = experimental”来尝试此操作。这将在计划于2月份进行的下一次定期更新中添加到发布分支中。
我很感谢您看一看。我将编辑我的问题以添加正在完成此工作的代码的主要部分。我没有使用搜索,但我没有对LocationRect做任何事情。我基本上只是用DirectionsManager添加航点和计算方向。 –
感谢您对此进行研究。你能想一想我能做些什么来解决这个问题吗? –
我相信当请求中有-180时,REST服务会失败。计算方向时尽量让地图放大一点。这应该会导致正在使用的较小的边界框不包含-180。 – rbrundritt