嗨,我正在尝试构建一个带有自动完成的Geo-Data (geonames.org API)的字段。
我想出了如何解决邮政编码输入和城市名称搜索的问题。我想把这两者都包括进去。如果我用城市名称搜索,它还会显示最近几个城市所有可能的邮政编码。
我希望你能帮我或者给我个提示。
我的代码是:
$(function () {
function log(message) {
$("#log").text(message);
$("#log").scrollTop(0);
}
$("#city").autocomplete({
source: function (request, response) {
$.ajax({
url: "http://api.geonames.org/postalCodeSearchJSON",
dataType: "jsonp",
data: {
postalcode_startsWith: request.term,
maxRows: 10,
country: "DE",
username: "username"
},
success: function (data) {
response($.map(data.postalCodes, function (item) {
return {
label: item.postalCode + "-" + item.placeName,
value: item.postalCode + "-" + item.placeName
}
}));
}
});
},
minLength: 2,
select: function (event, ui) {
log(ui.item ?
"Sie haben: " + ui.item.label + " ausgewählt ":
"Nichts ausgewählt " + this.value);
}
});
});发布于 2016-02-23 13:24:15
更新:
就像往常一样简单。不需要特殊代码,只需将数据更改为:
data: {
featureClass: "P",
maxRows: 10,
country: "DE",
placename_startsWith: request.term,
username: "yourusername"
}https://stackoverflow.com/questions/35576070
复制相似问题