【问题标题】:Bing maps get geolocation between two places failes必应地图获取两地之间的地理位置失败
【发布时间】:2014-02-18 13:27:14
【问题描述】:

我对两个文本框使用自动完成功能。使用此代码可以正常工作:

$('[id$=PlaceOfDeparture]:not(.ui-autocomplete-input), [id$=PlaceOfArrival]:not(.ui-autocomplete-input)').live('focus', function () {
    $(this).autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "http://dev.virtualearth.net/REST/v1/Locations",
                dataType: "jsonp",
                data: {
                    key: 'mykey',
                    q: request.term
                },
                jsonp: "jsonp",
                success: function (data) {
                    var result = data.resourceSets[0];
                    if (result) {
                        if (result.estimatedTotal > 0) {
                            response($.map(result.resources, function(item) {
                                return {
                                    data: item,
                                    label: item.name + '( ' + item.address.countryRegion+ ')',
                                    value: item.name
                                };
                            }));
                        }
                    }
                }    


            });
        },
        minLength: 1,
        select: function (event, ui) {
            $(this).val(ui.item.value);
            travel = $(this).closest('div').parent();
            $(this).change();
            updateMap();
        },
        open: function () {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },
        close: function () {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
        }
    });
});

});

效果很好。然后我想让 bing 地图在地图上的位置之间画一条线。

  bingMap = new Microsoft.Maps.Map(document.getElementById("map_canvas"), {
    credentials: "mykey",
    mapTypeId: Microsoft.Maps.MapTypeId.auto,
    enableSearchLogo: false,
    enableClickableLogo: false,
    showDashboard: false,
    center: new Microsoft.Maps.Location(55.7, 13.1833333),
    zoom: 10
});
Microsoft.Maps.loadModule("Microsoft.Maps.Directions", { callback: directionsModuleLoaded });

我用它来设置 bing 地图的航点:

 var startwaypoint = new Microsoft.Maps.Directions.Waypoint({ address: placeOfDeparture });
                bingDirections.addWaypoint(startwaypoint);

                // end
                var endwaypoint = new Microsoft.Maps.Directions.Waypoint({ address: placeOfArrival });
                bingDirections.addWaypoint(endwaypoint);

                // Calculate directions, which displays a route on the map
                bingDirections.calculateDirections();

前两个 ajaxpost 工作得很好,给了我“statusCode”:200 我读的应该是好的 :) 但是当我做 bingDirections.calculateDirections();它返回:

microsoftMapsNetworkCallback({"resolvedWaypoints":[[{"failed":true,"invalidCredentials":false,"inputType":0,"latitude":0,"longitude":0,"rooftopLatitude":0,"屋顶经度":0,"地址":null,"disambiguation":null,"locationIdentifier":null},{"failed":true,"invalidCredentials":false,"inputType":0,"latitude":0," longitude":0,"rooftopLatitude":0,"rooftopLongitude":0,"address":null,"disambiguation":null,"locationIdentifier":null}]]}, 'd6392');

【问题讨论】:

    标签: ajax bing-maps virtual-earth


    【解决方案1】:

    检查响应标头。可能有一个名为 X-MS-BM-WS-INFO 的属性设置为 1。这表明您的请求受到速率限制。如果您使用基本密钥(非企业/许可帐户)发出大量请求,并且您的帐户正在以超过免费使用条款的速率生成交易,则您的帐户受到速率限制。这导致请求返回为空。这样做是为了确保基本帐户不会影响企业用户的服务。请注意,自动完成不在使用条款范围内,并且可能是费率交易超出免费使用条款的原因。

    另请参阅此文档:http://msdn.microsoft.com/en-us/library/ff701703.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多