Brent
Brent

Reputation: 521

Implementing Google Places Autocomplete dropdown without the javascript library

I'm implementing a Google Places Autocomplete dropdown, but need to do the api communication on the server as to not expose the API key (project requirement). The querying and returning of suggested addresses from my server to the client is done and working. Now I just need to build the dropdown with the data.

Implementing the autocomplete dropdown widget is fairly simple using the places javascript library (new google.maps.places.Autocomplete(elem)), but is there a low effort way of doing it when you're not using that library? Or is there a way of using that library without exposing your api key?

Upvotes: 1

Views: 1202

Answers (1)

evan
evan

Reputation: 5701

If you need to implement Place Autocomplete in client-side JavaScript then you should use the client-side library. Otherwise you'll run into a bunch of issues such as CORS errors.

If what you're worried about is exposing the API key, then note that there's no need to because the key can (and should) be restricted with HTTP referrers. As long as it's restricted, it cannot be used from third-party domains. To learn more about API key restrictions check out Google's documentation.

Hope this helps!

Upvotes: 1

Related Questions