Skip to content

CORS error when trying to get google geocoding #273

@youradds

Description

@youradds

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions