Skip to content Skip to sidebar Skip to footer

Google Places Api Cors Error

I have a function in which I am using AJAX to make a call to the Google Places API, but this is returning a CORS error. The API is both a client and server API, thus the API does a

Solution 1:

As @geocodezip mentioned, rather than making another AJAX call, use the places library already included. Just make sure it's included in the query string like:

src="https://maps.googleapis.com/maps/api/js?key=[MY_KEY]&libraries=places" async defer

Then you'll have .getDetails() available for use.

var request = {
          placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4'
        };
    service = new google.maps.places.PlacesService(map);
    service.getDetails(request, callback);

    functioncallback(place, status) {
      if (status == google.maps.places.PlacesServiceStatus.OK) {
        createMarker(place);
      }
    }

Post a Comment for "Google Places Api Cors Error"