0

So I've tried using the Places Library from the Google Maps Platform, but I've been getting incorrect results when doing more than one request on locations near me. Basically, my code is trying to find nearby basketball courts based on a latitude and longitude. I've been getting the CORS error and I've been using a Chrome extension to get around it as a temporary fix (and it works fine). Now, I'm trying to set the headers to Access-Control-Allow-Origin: * to try and get around the error. The header info is likely not doing this correctly. My code is below (I want to keep using json and not jsonp because I saw that it's not as safe to use).

bask_preqdata = {
            key: myKey,
            radius: radi,
            location: lati +  "," + longi,
            keyword: "basketball court",
            headers: {'Access-Control-Allow-Origin': '*'}
        }

        $.get("https://maps.googleapis.com/maps/api/place/nearbysearch/json?", bask_preqdata, 
        function placeData(data) {
            gotPlaceData(data);
        }, 
        "json");

I'm trying to stick to the $.get call format. I've tried the $.ajax(settings)... call with the modified headers but it also didn't get around the CORS error. Any help would be greatly appreciated!

ProZude
  • 1
  • 1
  • Does this solve your problem - https://stackoverflow.com/questions/28359730/google-place-api-no-access-control-allow-origin-header-is-present-on-the-req? – random Feb 27 '20 at 01:00
  • 1
    `Access-Control-Allow-Origin` is a response header, not a request header. It has to be set by the server, not the client. – Barmar Feb 27 '20 at 01:06
  • I've done every "solution" to that post before, none worked for me :( – ProZude Feb 27 '20 at 01:07
  • I am using Xampp Apache for my local server, so I just need to configure the code to let it know about the header settings? Then if done correctly (in the js code), it will also work with server hosting platforms right? – ProZude Feb 27 '20 at 02:48

0 Answers0