Google Maps JavaScript API throws "ExpiredKeyMapError" when Geocoding API is enabled - google-maps

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.

Related

Google Map Rates/Charges

google map pricing is highly complex. Can someone tell whether the follow will be considered as three map accesses counted for charging. I am using Javascript APIs and render maps on a mobile web app.
showing a map in the client
Geocode an address
Add a marker on the map for the given location
Reference: https://developers.google.com/maps/billing/understanding-cost-of-use
showing a map in the client using the Google Maps Javascript API v3 is a "Dynamic Maps" load (requires loading the API)
Geocode an address is a "Geocoding" access
Add a marker on the map for the given location doesn't use any additional quota

Maps API keys for geocoding not working

I have read your answer on this.
Maps API keys for geocoding not working anymore?
Currently I am trying this:
https://maps.google.com/maps/api/geocode/json?address=n&sensor=true&key=apikeygoeshere
Giving me error:
This API project is not authorized to use this API.
Please suggest how can I complete my app. I am searching locations for my App.I can buy business plan later but for now I need to test for development.
I have following services on:
Google Maps Coordinate API, Google Maps Engine API, Google Maps Geolocation API, Google Maps JavaScript API v3, Google Maps SDK for iOS, Places API.
What you are referring to is not the Geolocation API. It is the Geocoding API. You need to enable the Geocoding API in your console. Please see the documentation.
Visit the APIs console at https://code.google.com/apis/console and log in with your Google Account.
Click the Services link from the left-hand menu in the APIs Console, then activate the Geocoding API service.
Hope this helps.
Try this URL,
You Don't have to enter API Key in URL
Just pass lat,lng in URL through a variable
http://maps.google.com/maps/api/geocode/json?latlng=-34.78,138.519&sensor=false
When you put your location (Capital Area Soccer League) in google map search, google plots the location in the map if it finds a correct geocodes but if it does not finds proper geocodes for the searched location then it shows suggestions of corrects locations in the dropdown. When you choose any of the locations from the dropdown - it has the correct lat long (geocodes) so it plots that in the map correctly.
So you should not use geocodes in the search rather open up a suggestions dropdown and when click on any of the suggested location then you have correct geocodes to plot in the map.

Google Maps API Webservices

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.

How to get locations of Google Maps Route?

How I can get coordinates (lat,lon) of route from url generated by google (like: http://goo.gl/maps/1gpxk).
Is there an API for that or anything else?
Thanks.
See the documentation. Make sure you read the Terms of Service.
Directions Web service
Google Maps Javascript API v3 Directions Service

How to get dynamically latitude and longitude on google maps?

I have country and address. How can I retrieve latitude and longitude from Google Maps V3?
I will use this to load the map.
EDIT
This is my actual code, but seems that Google API return this error : W[B].bindTo=function(a,b,c,d){var c=c|...R[p](this,wf,a);this.Pb&&this.Pb(a)};
SOLUTION
remove center: location,
You can retreive this with Geocoding Requests.
You can see my last project that I used this here. See function AddMarker in gmaps3.js for a working real world example. Basically I fetch addresses from database (using AJAX) and then convert them to lat/lon to make markers on the map.
You can use their ReST-API.
http://maps.google.com/maps/api/geocode/json?address=Berlin+Germany&sensor=false
The documentation is in The Google Geocoding API. You will have to do a http request e.g. $.get in jQuery to perform the query and then parse the JSON. Other output formats include XML. There's a JavaScript geocoder on their site as well.
You need to access geocoding.
http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding
http://code.google.com/apis/maps/documentation/geocoding/index.html