【发布时间】:2011-09-30 17:16:44
【问题描述】:
我正在尝试使用 Bing 地图 REST API 来查询给定搜索半径内所有实体的地址,给定名称。最终目标是像星巴克在这里所做的那样:Store Locator,但我使用了 Fiddler,看起来他们使用的是 6.3 API:/
如果有办法做到这一点,这似乎记录得很差。如果您上传自己的数据,有一些示例说明如何执行此操作,但如果您正在搜索应该已经在地图上的本地企业: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. :( ");
}
});
});
}
任何帮助将不胜感激!
【问题讨论】:
标签: jquery asp.net ajax geolocation bing-maps