jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 使用Bing Maps REST控件查找附近的实体大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用Bing Maps 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. :( ");
            }
        });
    });
}

任何帮助将不胜感激!!

解决方法

Bing Maps LOCATIOns API用于地理编码 – 即在地图上查找地址或地点.你想要做的是找到东西,然后把它们放在地图上.为此,您需要使用Bing API(而不是Bing Maps API).

Bing电话簿搜索REST服务应该为您提供所需的功能 – 这里有一个例:http://msdn.microsoft.com/en-us/library/dd251030.aspx电话簿搜索的每个结果都有一个纬度和经度属性,您可以使用该属性在地图上创建图钉.

@H_801_27@

大佬总结

以上是大佬教程为你收集整理的jquery – 使用Bing Maps REST控件查找附近的实体全部内容,希望文章能够帮你解决jquery – 使用Bing Maps REST控件查找附近的实体所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。