I had been using the following code, which was working fine for a week or so, i've come back to work on it further and it no longer seems to work. I am wanting to show localities only. Looking at Google's documentation "locality" is the correct option to do so. I was thinking that perhaps google changed the API or something. As soon as i switch it to geocode it works but shows all streets and places, which is not what I want. I also tried ["locality","political"] as well with no luck. What am I doing wrong here?
<script type="text/javascript">
function initialize() {
var input = document.getElementById('searchTextField');
var Newoptions = {
types: ["locality"]
};
var autocomplete = new google.maps.places.Autocomplete(input,Newoptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<input id="searchTextField" name="member_location" value="" type="text" >
Locality is not always provided in the results, so you have to provide a fallback if you're in an area with no locality, like administrative_area_level_3, though the only one you will always get is country, so you'd better have it fallback eventually to there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With