Reputation: 15404
I am using JQuery to get JSON data from the Google Maps Geodcode API using:
var jsonLtdLng="https://maps.googleapis.com/maps/api/geocode/json?address=Sydney&key=MY-KEY";
$.getJSON(jsonLtdLng, function (data) {
console.log(data);
});
The documentation says I require a Server API Key, but this is not server side code?
I tried making a Server API Key using my own routers IP address and it worked (but of course this is useless for any other users). I tried adding the web hosts IP and just got the error that the key is not authorised.
I know you can run it without a key for small quotas, but is that not advisable?
Would anyone know how to make this work? Do I have to do this in server side with PHP?
Upvotes: 1
Views: 2986
Reputation: 161334
The recommendation from Google in Issue 4921: Bug: missing CORS HTTP Header is:
You should really be using the Javascript client library. We are intentionally not setting CORS headers on this geocode service, as it is intended to be used by servers.
https://developers.google.com/maps/documentation/javascript/geocoding
If you are going to be using the geocoding service from javascript on the client use the Google Maps Javascript API v3 Geocoding Service with a browser key.
Upvotes: 1