我正在尝试使用Bing Maps REST API查询给定搜索半径内具有特定名称的所有实体的地址。最终目标是像星巴克在这里Store Locator所做的那样,但我使用了Fiddler,看起来他们正在使用6.3 API :/
如果有方法可以做到这一点,这似乎文档非常不完善。如果您上传自己的数据,则有一些如何执行此操作的示例,但如果您正在搜索应已在地图上的本地企业,则没有这些示例:Examples。到目前为止,这是我尝试过的...它返回的是Starbucks,俄勒冈州的结果。
这是在位置查询之前的代码,以防你想知道我在位置查询中使用的位置数据 - 它基本上来自用户的位置通过地理位置API:
任何帮助都将不胜感激!!
如果有方法可以做到这一点,这似乎文档非常不完善。如果您上传自己的数据,则有一些如何执行此操作的示例,但如果您正在搜索应已在地图上的本地企业,则没有这些示例:Examples。到目前为止,这是我尝试过的...它返回的是Starbucks,俄勒冈州的结果。
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. :( ");
}
});
});
}
任何帮助都将不胜感激!!