【问题标题】:bing maps upgrading from v7 to v8 error with userMapViewbing 地图从 v7 升级到 v8 错误与 userMapView
【发布时间】:2016-12-28 16:58:17
【问题描述】:

我正在将一个项目从使用 bing maps v7 ajax api 升级到使用 v8 api。我遇到了一个问题,我收到一条消息,说“找不到您输入的航路点”。所以我备份并修改了一个示例屏幕来做我正在做的事情,它工作正常。因此,我已将其范围(使用提琴手)缩小到为每个航路点进行的 REST 调用,在第一种情况下出现错误说 userMapView 超出范围,但在第二种情况下工作正常。我不太确定为什么示例代码与我的实际应用程序可能有所不同。这是两个网址。第一个是失败的:

https://dev.virtualearth.net/REST/v1/Locations/?q=Cincinnati%2C%20OH&o=json&culture=en-US&jsonp=Microsoft.Maps.NetworkCallbacks.f5de44&key=MY_BING_MAPS_KEY&maxResults=5&userMapView=39.18820190429691,-180,39.18820190429691,-180&inclnb=0&incl=

https://dev.virtualearth.net/REST/v1/Locations/?q=cincinnati%2C%20oh&o=json&culture=en-US&jsonp=Microsoft.Maps.NetworkCallbacks.f66617&key=MY_BING_MAPS_KEY&maxResults=5&userMapView=39.02836016935031,-85.12275695800781,39.34768093312603,-85.12275695800781&inclnb=0&incl=

如果我用第二个 URL 的参数替换第一个 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 = '';
    }
}

【问题讨论】:

    标签: rest bing-maps


    【解决方案1】:

    以前没见过这个问题,很奇怪。查看您的代码,如果您使用搜索模块进行地理编码,请不要设置边界选项并查看它是否可以解决问题。 bounds 属性用于设置 REST 请求的 userMapView 属性。如果这样可行,那么传入的 LocationRect 对象或搜索模块如何使用它可能存在问题。我将查看源代码,看看是否存在可能导致此问题的错误。

    更新 1:现在我看到您的编辑并看到您正在使用路线管理器,我可以看到 userMapView 是从地图中自动添加的。不知道为什么它会添加这样不正确的值。看起来他们添加了两次相同的坐标,而不是添加西北和东南坐标。将看看我是否可以通过挖掘代码来验证这一点。

    更新 2:我发现了代码中的错误。我已经与开发团队记录了这个问题,以便他们下次接触搜索管理器的代码时可以解决它。问题是西值被添加到 userMapView 请求中两次,但没有添加东值。

    更新 3:好消息,此错误现已在 Bing 地图的实验分支中得到解决。您可以通过将“&branch=experimental”添加到地图脚本 URL 来进行尝试。这将在计划于 2 月进行的下一次定期更新中添加到发布分支。

    【讨论】:

    • 感谢您的关注。我将编辑我的问题以添加正在执行工作的代码的主要部分。我没有使用 Search,也没有对 LocationRect 做任何事情。我本质上只是使用 DirectionsManager 添加航点并计算方向。
    • 感谢您对此进行研究。在此期间,您能想到我能做些什么来解决这个问题吗?
    • 我相信当请求中有 -180 时 REST 服务会失败。在计算方向时尝试将地图放大一点。这应该会导致使用不包括 -180 的更小的边界框。
    • 我发现唯一对我有帮助的是我使用了一个技巧来隐藏地图的 div 直到它准备好。该代码有另一个 div 位于地图的 div 顶部,当地图完成加载时,该 div 从 display:block 更改为 display:none。一旦我删除它,它就起作用了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 2017-02-21
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    相关资源
    最近更新 更多