I’ve read a few posts on this topic but can’t find the solution. I want to ensure my autocomplete returns addresses only in the UK (or at least favours the UK results).
It says here that I need to add the following HTML
function initialize() {
var optionsT = {
types: ['geocode'],
componentRestrictions: {country: "uk"}
};
var autocompleteT = new google.maps.places.Autocomplete(document.getElementById('TarPlacename'), optionsT);
}
But this made no difference, still the majority of results are US based, until I have almost completed the UK address I am only shows foreign addresses?
Also, the HTML I added shows on the page, how do I make it invisible?
You need to add
“< script >”(without quotes and spaces) at the beginning and “</ script >”(without quotes and spaces) at the end to run the script.
You need to un-tick “This element is visible on page load” to make the HTML element invisible.
Thank you @maheshkasindi I did this and all looks good but still the UK addresses are not populating until much later than other territories. Maybe it’ll take a while to reset or something as I only just added the script tags.
I’m curious to the pros and cons around using HTML like this as opposed to just using the native bubble search element, setting it to geographic places and using the native ‘limit results’ function of that element?
Yes. I added an invisible HTML element, put the code inside this wrapped around the < script > tags (without spaces and the closing tag) and set the Element ID on the input to match that of the Javascript.
The only other things I can think of are to move the HTML element so that it is not overlapping anything else and to double-check your Google API settings (both in Bubble and Google API Dashboard to ensure that the necessary APIs are enabled there).