What's the API Key for in Google Maps API V3?
As of June 22, 2016 Google Maps V3 no longer supports keyless access so you need to get a key for every (referrer-)domain which has never had a Google Map on it before.
Get your key here: https://developers.google.com/maps/documentation/javascript/get-api-key
and append it to the URL of the script like so:
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" type="text/javascript"></script>
If you do not provide an API key you will see this warning instead of your rendered map:and your browser's console will tell you the reason:
Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error
How can I Get Google Map Api v3 key?
Have you seen this link ?
Then you have to use it in your webpages with
- 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.
- Activate the Google Maps API v3 service.
- Click the API Access link from the left-hand menu. Your API key is available from the API Access page, in the Simple API Access section. Maps API applications use the Key for browser apps.
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
And replace YOUR_API_KEY
by the API key you just generated.
Here, initMap
is the name of the method executed once GoogleMaps is fully loaded ; you can remove or rename this parameter depending what you need
Do you experience any issue with this step-by-step ? It worked for me.
Google maps V3 API key usage
Don't forget the equals
.
src="https://maps.googleapis.com/maps/api/js?key=123456ABCDEFG&sensor=false"
Google Maps JavaScript API V3 - API Key and clientId
I think if the documentation says "All Maps API applications should load the Maps API using an API key," then that is the advice to follow. It's probably better advice than postings in a forum (including, perhaps, this one).
It's true that Version 3 will work without a key; but there is no guarantee that they will continue to do so, particularly in the light of the documentation; and using a key brings the benefits of statistics reporting.
The client ID is associated with an Enterprise licence, which raises some of the limits associated with a ordinary free key. Neither unlocks advanced features of the map; both allow usage reporting.
Determining Use of Google Maps API Key
The only current way for you to know the domains of the API Keys that are being used is to:
Restrict your API Key. By doing so, the other domains will be unable to use the API Key that is not in the list of referrers. See API Key Best Practices or,
Start fresh by creating a new Key and properly restrict it with the domains you are aware of. Then start migrating it to the sites that you built. Then eventually, delete the old key at least until June 11, as that will be the date when the changes will be implemented.
You can set Budgets Alerts which will notify you if you reach the conditions you set. You can cap your usage by setting consumer quota limits on a per-API basis from the Cloud Console.
I also encourage you to follow the API key best practices and,
Use these strategies detailed on the Optimization Guide
Does google maps javascript api-key (v3) need to be kept secret in HTML checked into github and if so, how?
V3 doesn't require a key, but there are some benefits to using one.
Note first off that this key is different than the old V2 key. It's generated from the APIs console (http://code.google.com/apis/console). You pass it the same way, with a key
parameter when loading the JS.
Benefits of having a key include usage reports in the console, and a way for Google to contact you if you're going over the quota regularly. You can also purchase additional quota through the console. Finally, if you're using the Places API, it requires the use of a key.
You can set allowed referrers, so that your key can't be used by others.
Google Map API v3 example from their site doesn't work without an API key but does with a Key. What am I doing wrong?
Move the google maps script include into the head. It has to be included before you call it.
Call your initMap function to run the function you set up. The function initMap()
has only been defined, but you haven't run it until then.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polylines</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>
<body>
<div id="map"></div>
<script>
// This example creates a 2-pixel-wide red polyline showing the path of William
// Kingsford Smith's first trans-Pacific flight between Oakland, CA, and
// Brisbane, Australia.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: {lat: 0, lng: -180},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
var flightPlanCoordinates = [
{lat: 37.772, lng: -122.214},
{lat: 21.291, lng: -157.821},
{lat: -18.142, lng: 178.431},
{lat: -27.467, lng: 153.027}
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
initMap();
</script>
</body>
</html>
Google Maps v3 API key won't work for local testing
UPDATE :
As of June 22, 2016 Google Maps V3 no longer support keyless access (any request that doesn't include an API key).
You can register for the key : https://developers.google.com/maps/documentation/javascript/get-api-key
and add it to your URL :
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" type="text/javascript"></script>
I have faced a similar issue with my application. I use the url without the client key for testing purposes and add the key before putting the code onto the production server. This is a workaround more than a solution and I am assuming that your usage for local testing will be low.
Testing server
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?sensor=SET_TO_TRUE_OR_FALSE">
</script>
Production Server <script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=SET_TO_TRUE_OR_FALSE">
</script>
URL : https://developers.google.com/maps/documentation/javascript/examples/If you check the following site and go to the basic map example you will find that the examples do not use a key. This was one of the differences between v2 and v3 of the maps that the key is not mandatory.
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
Keep in mind that omitting the key falls under the free Google Maps API licensing. If you need to track usage, you must supply at least the key. If you need more traffic, you need to supply your client ID (Google Maps for Work).https://developers.google.com/maps/licensing
Related Topics
Invoke a Callback at the End of a Transition
How to Get Month and Date of JavaScript in 2 Digit Format
Using Filesystem in Node.Js with Async/Await
Why Does JavaScript Getyear() Return 108
JavaScript Property with Three Dots (...)
Play 2.X: How to Make an Ajax Request with a Common Button
Printing a Web Page Using Just Url and Without Opening New Window
Way to Know If User Clicked Cancel on a JavaScript Onbeforeunload Dialog
How to Execute a Function on Pressing the Enter Key in an <Input> Field
How to Create an Auto-Complete Combobox
Why Do People Put Code Like "Throw 1; <Dont Be Evil>" and "For(;;);" in Front of JSON Responses
How Does Internationalization Work in JavaScript
JavaScript When to Use Prototypes
Access Properties of the Parent with a Handlebars 'Each' Loop
Access 'Data-' Attribute Without Jquery