1

I try to get data from API Google Places

axios.get('https://maps.googleapis.com/maps/api/place/details/json?placeid=...&key=mykey')
    .then(response => {
      commit('SET_REVIEWS', { list: response.data })
    }, error => {
      console.log(error)
    })                                                                                              

And after that i have this error enter image description here I know the error with CORS on server side, but what should i do?

Sergey Andreev
  • 1,398
  • 3
  • 16
  • 26
  • 2
    The only supported way to use the Places API endpoints is with the Places Library as outlined in the offcial documentation. See https://stackoverflow.com/questions/43443836/angular-cors-jsonp-and-google-maps-http-api-calls/43444274#43444274 and https://stackoverflow.com/questions/44336773/google-maps-api-no-access-control-allow-origin-header-is-present-on-the-reque/44339169#44339169 – sideshowbarker Dec 21 '17 at 06:54

2 Answers2

2

In my project I use NuxtJS and I found the solution. You have to make a request on the server side (nodeJS), not the client. As shown below, the method fetch allows you to do this and it works
https://nuxtjs.org/guide/vuex-store#the-fetch-method

xomena
  • 31,125
  • 6
  • 88
  • 117
Sergey Andreev
  • 1,398
  • 3
  • 16
  • 26
0

Simply create and call a webservice on your own server which in turn calls googles webservice.

The main code of your webservice could look like this, in PHP:

$url = 'https://maps.googleapis.com/maps/api/place/details/json?key=' . $key . '&placeid=' . $place_id; echo json_decode(file_get_contents($url), true);

rosell.dk
  • 2,228
  • 25
  • 15