我对两个文本框使用自动完成功能。使用此代码可以正常工作:
$('[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');