2

I'm using Geocomplete - jQuery Geocoding and Places Autocomplete Plugin and I'm trying to limit the results returned in the following way. I need:

  • Country: Australia
  • State: Queensland

with the suggestions limited to:

  • Post Code
  • Suburb

I can limit to AUS with no problem but the rest is proving difficult. Reading through the types I believe I need to use administrative_area_level_1 to get the State and then postal_code and neighborhood to limit the suggestions? I'm just totally stuck on how to do it.

$("input").geocomplete({
  country: 'AUS',
  types: ["postal_code", "neighborhood"], // Doesn't work
});
Mischa Colley
  • 123
  • 3
  • 13

1 Answers1

1

Try replacing types with type, because types is deprecated.

$("input").geocomplete({
    country: 'AUS',
    type: ["postal_code", "neighborhood"]
});

But since Google Maps API itself doesn't always return consistent results, it might be necessary to further filter response results. If you log geocode:result event's result to a console, you can see the whole material and decide what to with parts.

$("input").geocomplete({
    country: 'AUS',
    type: ["postal_code", "neighborhood"]
}).bind("geocode:result", function(event, result){
    console.log(result);
});

I needed to do similar thing like you and I found adr_address property to be quite useful. It is a HTML formatted string consisting of several span elements with self-descriptive classes, like:

<span class="street-address">Vippebakke</span>, <span class="postal-code">3740</span> <span class="locality">Svaneke</span>, <span class="country-name">Denmark</span>

So it can be appended somewhere invisible and then you can use particular elements inside it.

cincplug
  • 1,024
  • 5
  • 20
  • 38