Using the places library without a map on the same page

4,844 views
Skip to first unread message

Johannes Schill

unread,
May 18, 2011, 5:07:07 PM5/18/11
to Google Maps JavaScript API v3
Hello,

Is it possible to use the Places library - the autocomplete feature[1]
without having a map on the same page? Im trying to follow the
example[2] but when i remove the map - and the code related to the map
- the autocomplete stops showing "establishments" and only "geocodes"
are being included in the result. Maybe my default bounds are bad in
my javascript[3]?

[1] http://code.google.com/apis/maps/documentation/javascript/places.html#places_autocomplete
[2] http://code.google.com/intl/sv/apis/maps/documentation/javascript/examples/places-autocomplete.html
[3] http://www.jspaste.com/?id=283

Thanks!

Thor Mitchell (Google Employee)

unread,
May 18, 2011, 7:50:41 PM5/18/11
to google-map...@googlegroups.com
Hi Johannes,

As part of the Maps API, the Places library is covered by the Maps API Terms of Service, which does require it be used in conjunction with a map. This does not mean you must always pass in a map bounds when using Autocomplete, but it does mean that your app must use a map in some way, even if it's just a small thumbnail map of the Place selected by the user using Autocomplete.

With regards to why the establishments are not shown, in the absence of bounds to constrain the predictions made by Autocomplete, the geocode matches outrank the establishment matches, thus being returned in preference to establishments.

Many thanks,

Thor.

Johannes Schill

unread,
May 19, 2011, 2:42:04 AM5/19/11
to Google Maps JavaScript API v3
Hi Thor!

Thanks for your quick reply. To rephrase: we're using a map, but its
not shown until the user clicks on a search result from the
autocomplete feature. I'll double-check the terms. Isnt it possible to
manually feed the Autocomplete with manually set bounds instead of the
map.getBounds()?

I tried another approach, using the webservice[4] instead, but it
didnt work as I expected; "debaser stockholm" gave me 3 hits,
"stockholm debaser" 1 hit, "debaser" 0 hits. I only included the
required parameters to make the search as world-wide as possible. Is
it a bit shaky or is that expected?

[4] http://code.google.com/apis/maps/documentation/places/autocomplete.html

Thanks again and hi from Sweden.

Johannes

Spotvite

unread,
May 20, 2011, 2:41:21 AM5/20/11
to google-map...@googlegroups.com
Hey there, question here

How are you able to load Google places int he first places?

I keep getting google.maps.places is undefined even when the libraries=places

Just wondering

Thor Mitchell (Google Employee)

unread,
May 25, 2011, 4:42:45 AM5/25/11
to google-map...@googlegroups.com
Hi Johannes,

You can construct your own google.maps.LatLngBounds() object to pass in rather than obtaining one from the map:


Without some form of bounds restrict you are unlikely to get any establishment predictions, as major cities totally outrank businesses.

Many thanks,

Thor.

Chris Broadfoot

unread,
May 25, 2011, 5:59:39 AM5/25/11
to google-map...@googlegroups.com
On Thu, May 19, 2011 at 7:07 AM, Johannes Schill <johanne...@gmail.com> wrote:
are being included in the result. Maybe my default bounds are bad in
my javascript[3]?

Yeah, your default bounds are basically the whole world. You may as well omit them!

You really want something like this:
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);

This will ensure the Autocomplete box always gives you completions based on the current viewport of your map.

Chris

Chris Broadfoot

unread,
May 25, 2011, 6:00:45 AM5/25/11
to google-map...@googlegroups.com
Oh, and you can defer this binding until you create your map, too. Just call "bindTo" once you create your Map object.

--
http://twitter.com/broady

Gary Little

unread,
May 25, 2011, 12:15:24 PM5/25/11
to Google Maps JavaScript API v3
Chris,

Neat bindTo trick! No need to set up an event listener... Saved me
several lines of code.

Gary

On May 25, 2:59 am, Chris Broadfoot <c...@google.com> wrote:
> On Thu, May 19, 2011 at 7:07 AM, Johannes Schill
> <johannes.sch...@gmail.com>wrote:

Chris Broadfoot

unread,
May 25, 2011, 9:13:10 PM5/25/11
to google-map...@googlegroups.com

On Thu, May 26, 2011 at 2:15 AM, Gary Little <ga...@luxcentral.com> wrote:
Neat bindTo trick! No need to set up an event listener... Saved me
several lines of code.

Yeah, I should probably add this to the sample code :)
Reply all
Reply to author
Forward
0 new messages