Google Places Autocomplete limit to neighborhood

admin

Administrator
Staff member
I've successfully integrated the <a href="https://github.com/ubilabs/geocomplete" rel="nofollow">Geocomplete jquery plugin</a> on a wordpress site. My issue is that I cannot limit the autosuggestion results to neighbourhood or sublocality. I've revised the Google Place types thoroughly but my results are always just the same. I know I'm doing something incorrectly somewhere. Here's what I have so far:

Code:
add_action( 'wp_head', 'add_geocomplete_script' );

function add_geocomplete_script() {
   ?&gt;
   &lt;script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCJ1Bgyx1jSN3aRFB3uUkLLntXCONZfOyM&amp;libraries=places"&gt;&lt;/script&gt;
   &lt;script src="&lt;?php echo get_stylesheet_directory_uri() ?&gt;/js/jquery.geocomplete.js"&gt;&lt;/script&gt;
   &lt;script src="&lt;?php echo get_stylesheet_directory_uri() ?&gt;/js/logger.js"&gt;&lt;/script&gt;
   &lt;?php 
} 

function woocommerce_checkout_autocomplete(){
?&gt;
    &lt;script&gt;
        jQuery(document).ready(function() {

            var options = {
                //types: ['(cities)'],
                //types: ['sublocality'],
                //componentTypes: ['neighborhood'],
                types: ["geocode", "sublocality"],
                country: 'za'
            };

            jQuery("#billing_myfield8").geocomplete(options);

            jQuery("#billing_myfield8").on("keyup", function() {
                //jQuery("#billing_myfield8").trigger("geocode");
                console.log('You typed in the input box');
            });
        });

    &lt;/script&gt;

&lt;?php
}

add_action( 'wp_footer', 'woocommerce_checkout_autocomplete' );

With the above code I'm still able to search for an address, eg. 112 Nowhere Street. It doesn't filter the results.