我試圖使用Bing Maps REST API查詢給定搜索半徑內給定名稱的所有實體的地址。最終目標是做類似於星巴克在這裏做的事情:Store Locator,但我使用了Fiddler,看起來他們使用的是6.3 API:/使用Bing Maps REST控件查找附近實體
如果有辦法做到這一點,那麼這似乎很差。如果您上傳自己的數據,有一些如何做到這一點的例子,但如果您正在尋找本應該已經在地圖上的本地企業,則不會有這樣的例子:Examples。這是我迄今爲止嘗試過......它返回星巴克,俄勒岡州:
var query = 'starbucks';
_map.getCredentials(function (credentials) {
$.getJSON('http://dev.virtualearth.net/REST/V1/Locations/' + query + '?key=' + credentials + '&lat=' + position.coords.latitude + '&long=' + position.coords.longitude + '&limit=25&jsonp=?&s=1',
function (result) {
if (result.resourceSets[0].address != 'undefined') {
var address = result.resourceSets[0].address;
alert(address);
}
else {
$("#results").html("Oops! It appears one or more of the addresses you entered are incorrect. :(");
}
});
});
這是在前面的情況下的位置查詢你想知道的位置數據是什麼,我使用的代碼位置查詢 - 它本質上來自用戶通過地理定位API的位置:
var _map;
$(document).ready(function() {
if (Modernizr.geolocation) {
$(".geofallback").hide();
}
else {
$(".geofallback").show();
}
$.post("Home/Key", { "func": "Key" }, function (data) {
// Create a Bing map
_map = new Microsoft.Maps.Map(document.getElementById("map"),
{ credentials: data, mapTypeId: Microsoft.Maps.MapTypeId.ordnanceSurvey });
});
// Get the current position from the browser
if (!navigator.geolocation) {
$("#results").html("This browser doesn't support geolocation, please enter an address");
}
else {
navigator.geolocation.getCurrentPosition(onPositionReady, onError);
}
});
function onPositionReady(position) {
// Apply the position to the map
var location = new Microsoft.Maps.Location(position.coords.latitude,
position.coords.longitude);
_map.setView({ zoom: 18, center: location });
// Add a pushpin to the map representing the current location
var pin = new Microsoft.Maps.Pushpin(location);
_map.entities.push(pin);
var query = 'starbucks';
_map.getCredentials(function (credentials) {
$.getJSON('http://dev.virtualearth.net/REST/V1/Locations/' + query + '?key=' + credentials + '&lat=' + position.coords.latitude + '&long=' + position.coords.longitude + '&limit=25&jsonp=?&s=1',
function (result) {
if (result.resourceSets[0].address != 'undefined') {
var address = result.resourceSets[0].address;
alert(address);
}
else {
$("#results").html("Oops! It appears one or more of the addresses you entered are incorrect. :(");
}
});
});
}
任何幫助將不勝感激!
謝謝阿拉斯泰爾!我給這個一杆。這應該工作,一如既往,我一定會確認這是被接受的答案,併發佈一個工作代碼示例 – Jordan
正如注:電話簿REST服務不包括開放時間和商業網站Url,但Bing Maps Search SOAP服務確實包含該數據如果您需要它,出於某種原因,Bing地圖搜索API不會提供一個REST接口(奇怪的是,所有其他服務都可以)。 – Junto
現在只需留言給任何人看:這不再存在。 – Seiyria