Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS error when trying to get google geocoding #273

Open
youradds opened this issue Jan 22, 2019 · 4 comments
Open

CORS error when trying to get google geocoding #273

youradds opened this issue Jan 22, 2019 · 4 comments

Comments

@youradds
Copy link

Hi,

I'm trying to create a function on my site that will enable a user to click a button, and then search based on their location. I'm trying to use Googles geocoder feature:

                navigator.geolocation.getCurrentPosition(function(position) {

                    reqwest({
                        url: 'https://maps.googleapis.com/maps/api/geocode/json',
                        type: 'json',
                        method: 'post',
                        data: { latlng: position.coords.latitude + "," + position.coords.longitude, key: 'xxxx' },
                        error: function (err) { },
                        success: function (data) {

                            console.dir(data)

                        }
                    });

                });

This tries to run, but I get an error thrown back:

Access to XMLHttpRequest at 'https://maps.googleapis.com/maps/api/geocode/json' from origin 'https://m.mysite.org' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

The headers are correct as far as I can see:

https://ibb.co/pxNGGKd

Any ideas what to try next?

Thanks

Andy

@sapabg
Copy link

sapabg commented Nov 29, 2019

Make sure you are not sending any additional headers with your request.
I had the same problem because of my JwtInterceptor adding 'Authorisation' header to google requests.

@urmanzaru
Copy link

@sapabg thanks I was occupying JWT.

@deepshah4855
Copy link

Thanks @sapabg
I had the same issue and your answered helped me to resolve it.

@samharvey44
Copy link

Cheers @sapabg sorted my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants