Autocomplete Filter Workaround
HTML
<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<div id="root">
<label for="place">Autocomplete</label>
<input type="text" id="place" style="width:200px;"/>
<div id="result"></div>
</div>
CSS
#result {
position: fixed;
background-color: #fff;
filter:alpha(opacity=70);
-moz-opacity:0.7;
-khtml-opacity: 0.7;
opacity: 0.7;
z-index: 10000;
border: 1px dotted black;
color:black;
display:none;
}
JavaScript
function initMultipleRestrictions() {
$("#place").on("keyup", function (evt) {
var inputData = $("#place").val();
service = new google.maps.places.AutocompleteService();
var request1 = {
input: inputData,
types: ['(cities)'],
componentRestrictions: {country: 'de'},
};
var request2 = {
input: inputData,
types: ['(cities)'],
componentRestrictions: {country: 'at'},
};
var request3 = {
input: inputData,
types: ['(cities)'],
componentRestrictions: {country: 'ch'},
};
$('#result').empty();
service.getPlacePredictions(request1, callback);
service.getPlacePredictions(request2, callback);
service.getPlacePredictions(request3, callback);
});
function callback(predictions, status) {
var resultData = '';
for (var i = 0, prediction; prediction = predictions[i]; i++) {
resultData += '<div>' + prediction.description + '</div>';
}
if($('#result').html() != undefined && $('#result').html() != ''){
resultData = $('#result').html()+ resultData;
}
if(resultData != undefined && resultData != ''){
$('#result').html(resultData).show();
}
}
}
google.maps.event.addDomListener(window, 'load', initMultipleRestrictions);
$( document ).ready(function() {
initMultipleRestrictions();
});