小编Ace*_*tar的帖子

如何按用户位置过滤Bing Location API结果以自动完成?

我有这个功能,根据用户输入的地址返回bing地址建议.我已经指定了userLocation,但结果并不像我想象的那样准确.我还有什么额外的事吗?如果必须,我可以手动指定州或邮政编码,但我宁愿避免进行后期处理.

例如,键入111将返回111,NY,111 Sweden,111 Denmark的结果.我想将此限制为仅限于美国,并且仅限于几个我可以硬编码的状态.当我在数据中手动指定postalCode的选项时,它会覆盖我在查询中使用的内容.

    var geolocate = function(options) {
    $.ajax({
        url: "http://dev.virtualearth.net/REST/v1/Locations",
        dataType: "jsonp",
        data: {
            key: "KEY",
            q: options.address,
            userLocation: options.latitude + ',' + options.longitude,
            maxResults: options.maxResults,
        },
        jsonp: "jsonp",
        success: function(data) {
            if (options.success instanceof Function) {
                options.success(data);
            }
        },
        error: function(xhr, status, text) {
            alert('ERROR:\n');
        }
    });
};
Run Code Online (Sandbox Code Playgroud)

jquery bing-maps jquery-autocomplete bing-api

5
推荐指数
1
解决办法
1513
查看次数

标签 统计

bing-api ×1

bing-maps ×1

jquery ×1

jquery-autocomplete ×1