Just A Guy
Just A Guy

Reputation: 159

Using node/vuejs, how to make google place API request on client side

I am using vuejs which runs as a single page application in the browser, so any API calls I am making are using axios. Unfortunately googles APIs block any requests through axios due to CORS. I have tried various npm packages to try and solve this, including "official" google maps package, but I still run into CORS issues.

I am positive there must be a way to do a placeid search through the browser using one of their javascript libraries, but I can't for the life of me find any good articles or examples to see how it is done.

I have google autocomplete working, and creating google maps through geocode is no problem, just can't find anything related to placeid search.

Here is an example of the request I am trying to make taken from googles docs.

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=YOUR_API_KEY

Can anyone provide a solution or link to an explanation on how to do this properly through javascript library, or through API call without running into CORS problems?

Upvotes: 1

Views: 1651

Answers (1)

ittus
ittus

Reputation: 22393

Your link to Google Maps Package is Node.js package (server side). That's why you have CORS issue.

If you're building a client-side application, take a look at the Places SDK for Android, the Places SDK for iOS, and the Places Library, Maps JavaScript API.

If you want to use it Google Maps on client side, you should use Maps JavaScript API

Upvotes: 4

Related Questions