I have been using the Google Maps Geocoding API Webservice for a few months now, and just recently it is giving me this error:
XMLHttpRequest cannot load http://maps.googleapis.com/maps/api/geocode/json?address=1600%2BAmphitheatr…in%2BView%2C%2BCA&sensor=false. Origin is not allowed by Access-Control-Allow-Origin.
I am using the following code:
$.getJSON( "http://maps.googleapis.com/maps/api/geocode/json",
{ address : "1600+Amphitheatre+Parkway,+Mountain+View,+CA", sensor : "false" },
function(data) {
if (data.status == "OK") {
alert("ok!");
}
});
According to
https://developers.google.com/maps/documentation/geocoding/
I should be able to use the webservice api as above.
I've also enabled the Google Maps v3 API and the Static Maps API in the Google API Console and set my domains to be allowed referrer domains but to no avail.
Anyone know why this suddenly stopped working and how I can fix it? I'd like to be able to keep using the webservices as opposed to the Javascript API if possible.
Related
I am testing the Google Places API on the Flutter Android app.
When I send a request to the API I get a JSON result with the following error message:
This IP, site or mobile application is not authorized to use this API key.
To build the request, I went to the Google API console and generated my Android API Key based on my application package.
I'm using Google Maps on the app and trying to make a request to the Places API.
I put both Application restrictions and API restrictions in Google API console using package name and SHA1
Without restrictions Places API work but with restrictions it's not working.
I use Google Maps JavaScript API for the map related matters and about to use Google Geocoding API to reverse the lat and lng to formatted address while users click on the map.
Everything works smoothly while I only use Maps JavaScript API until I enabled the Geocoding API. When I refreshed my page, I received error: Google Maps JavaScript API error: ExpiredKeyMapError.
To fix it is easy, simply disabled the Geocoding API fixed and apparently I can't use any features in Geocoding API anymore.
I also tried to generate a new API key and waited more than 2 hours but the problem is still there.
This is how I load the API and services
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=geocoding,places"></script>
How to properly use Maps JavaScript API and Geocoding API together?
Geocoding code to get address from lat and lng
var latLngToAddress = function (lat, lng) {
var latLng = {lat: lat, lng: lng},
geocoder = new google.maps.Geocoder;
geocoder.geocode(
{location: latLng},
function (results, status) {
console.log(results);
}
);
};
I get error Geocoding Service: This API project is not authorized to use this API. for doing above. If I enable the Geocoding service, then everything goes back to the original quesntion - the JS API will receive error ExpiredKeyMapError
I cannot guarantee the solution always work but this is how I solved it.
Disable the Geocoding API
Visit a Geocoding API request such as https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY and receive error.
Enable the Geocoding API within the project.
Visit a Geocoding API request again such as https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY and receive success.
Refresh the project page and both JavaScript and Geocoding APIs work smoothly now.
https://developers.google.com/maps/documentation/javascript/libraries
geocoding is not one of the available libraries in Google Maps Javascript API v3.
The API you have enabled is the Geocoding Web Service. You don't need it within a JS API project. To geocode/reverse geocode, simply use the google.maps.Geocoder class.
Here is my solution to my question and this solution is not guaranteed to work in many other cases.
Disable the Geocoding API
Visit a Geocoding API request such as https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY and receive error.
Enable the Geocoding API within the project.
Visit a Geocoding API request again such as https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY and receive success.
Refresh the project page and both JavaScript and Geocoding APIs work smoothly now.
Simply you need to disable the API and again Enable it within your project before using it and refresh all your work again.
I have develop an iPhone Application that have Google Api https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=API_KEY
if I have use Public apikey then its working fine but when I generate ristricted api key from google concole then api is not working and give error
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 27.109.**.**, with empty referer",
"results" : [],
"status" : "REQUEST_DENIED"
}
I have added valid bundle Id when I generate restricted Api key.
please give me solution Thanks in advance.
You are calling a web service (Geocoding API). Please note that web services support only IP address restriction. The iOS app restriction is not valid for web services, it works only with Google Maps SDK for iOS. You can find information about restrictions supported by each API in this document:
https://developers.google.com/maps/faq#keysystem
In order to use a restricted API key with Geocoding API from iOS app you will need to create your own intermediate server and execute calls to Google from your server. In this case you can protect an API key with IP address of your server. The app will request information from your server and you server will call Google and pass back results.
I am running an application on :
http:// myFakedomain.com:4502/
Application accesses Google MAP API. I registered the domain as myFakedomain .com for Google MAP , and getting :
Google Maps API error: UnauthorizedURLForClientIdMapError
When setting the URL for Google MAP , http:// myFakedomain.com:4502/ is it different than http:// myFakedomain. com ?
What URL should be used to set Google MAP API ?
The error message indicates that you are using the client ID. In this case you should authorize URLs in Google maps for Work support portal as described in
https://developers.google.com/maps/premium/previous-licenses/clientside/auth#register-urls
If you still have issues with this you should file an issue via your support portal.
I have the following Google Developer Console APIs with ON status:
Google Maps Embed API
Google Maps Javascript API v3
Static Maps API
BigQuery AP
Google Cloud SQL
Google Cloud Storage
Google Cloud Storage JSON API
I have the following link in an HTML email:
<img src='http://maps.google.com/staticmap?center=-15,-47&zoom=11&size=600x200&key=myKey'/>
But I never get an image. The key works OK for an embedded map using an iframe.
What am I doing wrong?
If you are using Google static Map API, you should use this URL:
http://maps.googleapis.com/maps/api/staticmap?center=-15,-47&zoom=11&size=600x200&key=myKey
Of course, replace 'myKey' to your valid key.
It won't work because you're trying to put it in an email, browsers work differently to email clients. Email clients block iframes for security purposes, see:
Is there no way to embed a Google Map into an HTML email?
You can check if your api key is working using the Google Maps API console https://code.google.com/apis/console/?pli=1
Update
also you might want to update the bit of the string 'myKey' with your api key :)