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

Ace*_*tar 5 jquery bing-maps jquery-autocomplete bing-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)

Ace*_*tar 1

事实证明,这实际上会实现我的预期(除非测试证明不是这样),我将地址指定为单个参数 q,但如果我与 userLocation 结合指定 addressLine,它会按预期过滤结果。

var geolocate = function(options) {
    $.ajax({
        url: "http://dev.virtualearth.net/REST/v1/Locations",
        dataType: "jsonp",
        data: {
            key: "KEY",
            addressLine: options.address,
            countryRegion: 'US',
            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\n');
        }
    });
};
Run Code Online (Sandbox Code Playgroud)