Places Autocomplete: the "types"-option seems ignored

2,379 views
Skip to first unread message

Johannes Schill

unread,
May 19, 2011, 7:55:16 AM5/19/11
to Google Maps JavaScript API v3
Hello,

The "types"-option in the places autocomplete[1] seems to be ignored.
Im using the following code:

var options = {
bounds: currentBounds,
types: "establishment"
};
autocomplete = new google.maps.places.Autocomplete(input, options);

I still get cities and other geocode hits. Any hints?

[1] http://code.google.com/apis/maps/documentation/javascript/places.html#places_autocomplete

Thanks.

Luke Mahé

unread,
May 19, 2011, 1:21:52 PM5/19/11
to google-map...@googlegroups.com
Can you please include a link to your example or include the query and location that you are using.

Thanks

-- Luke



--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Johannes Schill

unread,
May 19, 2011, 3:54:28 PM5/19/11
to Google Maps JavaScript API v3
Sure!

I simply copied the example and added the "types" option according to
the documentation:
http://projects.polyester.se/gmaps/places-autocomplete.html

I get countries, cities... everything just like the original example
without the option:
http://code.google.com/apis/maps/documentation/javascript/examples/places-autocomplete.html


Thanks alot.

Johannes



On May 19, 7:21 pm, Luke Mahé <lu...@google.com> wrote:
> Can you please include a link to your example or include the query and
> location that you are using.
>
> Thanks
>
> -- Luke
>
> On Thu, May 19, 2011 at 4:55 AM, Johannes Schill
> <johannes.sch...@gmail.com>wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > The "types"-option in the places autocomplete[1] seems to be ignored.
> > Im using the following code:
>
> > var options = {
> >  bounds: currentBounds,
> >  types: "establishment"
> > };
> > autocomplete = new google.maps.places.Autocomplete(input, options);
>
> > I still get cities and other geocode hits. Any hints?
>
> > [1]
> >http://code.google.com/apis/maps/documentation/javascript/places.html...
>
> > Thanks.
>

Rossko

unread,
May 19, 2011, 4:26:32 PM5/19/11
to Google Maps JavaScript API v3
> I simply copied the example and added the "types" option according to
> the documentation:http://projects.polyester.se/gmaps/places-autocomplete.html

If I type sm with 'geocodes' (addresses?) selected I get e.g. Small
Street
If I type sm with 'establishments' selected I get e.g. Small Bar
Seems to work as intended?

If you change the selection part way through typing, it doesn't change
the existing suggestion list, no-one told it to. If you want that to
happen you'll need to add some code to do that.

Johannes Schill

unread,
May 20, 2011, 4:12:18 AM5/20/11
to Google Maps JavaScript API v3

On May 19, 10:26 pm, Rossko <ros...@culzean.clara.co.uk> wrote:
> > I simply copied the example and added the "types" option according to
> > the documentation:http://projects.polyester.se/gmaps/places-autocomplete.html
>
> If I type sm with 'geocodes' (addresses?) selected I get e.g. Small
> Street
> If I type sm with 'establishments' selected I get e.g. Small Bar
> Seems to work as intended?

Correct, changing to 'establishment' by clicking the radiobutton works
as intended. But if you want the autocomplete to default on
establishments, it doesnt seem to work. In my source I added the
parameter, according to the manual:

---code---
var options = {
bounds: defaultBounds,
types: 'establishment'
};
---end code---

I also tried using the same method as clicking the radio button:

---code---
autocomplete.setTypes(['establishment']); // note: sending an array
here
---end code---

But unfortunately none of them seems to work, since typing sm returns
small street in both cases?

Thanks for your help.

Cheers
Johannes

Johannes Schill

unread,
May 20, 2011, 4:26:28 AM5/20/11
to Google Maps JavaScript API v3
I managed to get this working now in the morning in two different
ways. Some sleep helped me solve the problem. Here's how i did it:

If you're sending in 'establishment' in the option-parameter it has to
be an array:

---code---
var options = {
bounds: defaultBounds,
types: ['establishment'] // <- See here!
};
autocomplete = new google.maps.places.Autocomplete(input, options);
---end code---

It's also possible to use the autocomplete.setBounds()-method but i
had to put it in my bounds_changed-event (which is called upon page
load).

---code---
google.maps.event.addListener(map, 'bounds_changed', function() {
autocomplete.setTypes(['establishment']);
autocomplete.setBounds(map.getBounds());
});
---end code---

Yay.

Thanks for your input.

Cheers
Johannes

On May 20, 10:12 am, Johannes Schill <johannes.sch...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages