【问题标题】:How to add tags using Geolocation with Tags Input?如何使用带有标签输入的地理位置添加标签?
【发布时间】:2015-07-30 23:49:57
【问题描述】:
【问题讨论】:
标签:
autocomplete
google-geolocation
bootstrap-tags-input
【解决方案1】:
我使用带有引导标签输入的 Twitter Typeahead 的解决方案:
var locations = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('formatted_address'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
identify: function (obj) {
return obj.place_id;
},
remote: {
url: 'https://maps.googleapis.com/maps/api/geocode/json?address=%QUERY&language={YOUR_LANGUAGE}&key={YOUR_MAPS_API_KEY}',
wildcard: '%QUERY',
rateLimitWait: 100,
transform: function (response) {
if (response.status === 'OK') {
return response.results;
} else {
return [];
}
}
}
});
$('input').tagsinput({
itemValue: 'place_id',
itemText: 'formatted_address',
typeaheadjs: [{
highlight: true
}, {
displayKey: 'formatted_address',
source: locations
}],
trimValue: true
});