首先,需要确保在调用Bing Maps Rest API时使用正确的URL和参数。如果问题仍然存在,则需要检查所使用的响应格式,以确保匹配。例如,如果您希望使用JSON响应,则应将“output”参数设置为“json”。此外,确认所有参数都正确编码。以下是一个示例请求,该请求使用JSON格式接收响应:
var request = new XMLHttpRequest();
var outputFormat = "json";
var bingMapsKey = "";
var searchAddress = encodeURIComponent("1600 Amphitheatre Parkway, Mountain View, CA");
var requestUrl = "https://dev.virtualearth.net/REST/v1/Locations?query=" + searchAddress + "&output=" + outputFormat + "&key=" + bingMapsKey;
request.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
var response = JSON.parse(this.responseText);
console.log(response);
}
};
request.open("GET", requestUrl, true);
request.send();