Google Places Autocomplete API

413 views
Skip to first unread message

amnesia7

unread,
Jun 28, 2011, 9:44:15 AM6/28/11
to google-map...@googlegroups.com
I'm trying to create my own version of the Google Places Library Autocomplete (similar to the Google Places Autocomplete library but different enough for me to need to create my own).
 
I've setup an API key and have created a test page to start with.
 
I've tried to use jquery with getJson to load the request url but I keep getting security violation / no results / AJAX status 0 but if I download the data and put it in a local file on the webserver its fine. The web seems to imply that I need to use a json callback to get around the security issues of calling json from another webserver, ie Google Maps', but I can't figure out what this looks like.....after numerous attempts. I've seen the webpage about eval('(' + response + ')') but not sure how to apply this either.
 
Can someone offer some straight forward javascript that will show how to load the json response from the Google Places API (http://code.google.com/apis/maps/documentation/places/autocomplete.html), just on pageload will do, that I could then apply to my autocomplete?
 
Thanks

amnesia7

unread,
Jun 30, 2011, 4:54:56 PM6/30/11
to Google Maps JavaScript API v3
If I use (obviously the input=value will be based on the content of
the text field once I get it working but just static call for now)...:

$.getJSON("https://maps.googleapis.com/maps/api/place/autocomplete/
json?
sensor=false&key=xxxxxx&location=50.741357,-1.963828&input=bourne",
function(data) {
alert(data.predictions[0].description);
});

...it fails to load a response but if I manually navigate to the json
web address, download the json file, upload it to my web server as a
static file the following script will work fine (even though both
contain the same content):

$.getJSON("json.js", function(data) {
alert(data.predictions[0].description);
});

I assume this is because it is trying to cross domains.

Should there not be a json callback function available for use with
this API because I couldn't find one on the documentation page?

The other option I can think might work is to download the json file
using php with each request/keypress from my autocomplete but will
this not mean that the quota limits are against my web server's ip
address rather than the user's ip address if it were a javascript
request?

Col

Barry Hunter

unread,
Jun 30, 2011, 6:47:03 PM6/30/11
to google-map...@googlegroups.com
Google have said they dont support calling the Places API directly from browser 

You either need to use the offical Javascript API. 

Or make calls from a server.

Not sure why you are worried about using quota, as the Quota is based on your API key not IP address. 



--
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.


amnesia7

unread,
Jul 1, 2011, 8:57:43 AM7/1/11
to Google Maps JavaScript API v3
Thanks I must've missed where it said they don't support calling it
from the browser.

In that case, if I don't want to use the actual Google Places text
input Autocomplete, I'll need to make each call to it via my web
server then.

I know 100,000 sounds like a lot for a quota limit but I wondered
whether this may get used up quicker than expected if its an
autocomplete field (a single user could account for 5-10 hits before
they decide on a suggestion). I suppose even then though that still
allows 10,000 users per day though.

It must've been the quota for something else that I read that was
based on IP address.

Thanks for replying Barry.
> >http://groups.google.com/group/google-maps-js-api-v3?hl=en.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages