0

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

$('[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,"rooftopLongitude": 0,"address":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');

4

1 回答 1

0

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

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

于 2014-02-19T00:09:20.077 回答