How to use google maps without api key
Asked Answered
L

9

36

I am using the following code to use get-directions in google maps. But when I run this from other machines, it is showing the error "invalid api key". How can one use this same map without an api key?

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw" type="text/javascript"></script>
    <style type="text/css">
    body {
      background:#FFE1C7;
      font-family: Verdana, Arial, sans serif;
      font-size: 11px;
      margin: 2px;
    }
table.directions th {
      background-color:#EEEEEE;
    }

    img {
      color: #000000;
    }
    </style>
    <script type="text/javascript">

    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    
    function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
    
        setDirections("Bangalore", "Mysore", "en_US");
      }
    }
    
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }
    
    function handleErrors(){
     if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
       alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
     else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
       alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
     
     else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
       alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
    
    //   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
    //     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
       
     else if (gdir.getStatus().code == G_GEO_BAD_KEY)
       alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
    
     else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
       alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
      
     else alert("An unknown error occurred.");
    }
    
    function onGDirectionsLoad(){
        // Use this function to access information about the latest load()
        // results.
    
        // e.g.
        // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
      // and yada yada yada...
    }

    </script>
Lynettalynette answered 27/9, 2012 at 6:11 Comment(1)
see this ...#2187510Ambler
G
32

Note : This answer is now out-of-date. You are now required to have an API key to use google maps. Read More


you need to change your API from V2 to V3, Since Google Map Version 3 don't required API Key

Check this out..

write your script as

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
Groove answered 27/9, 2012 at 6:22 Comment(7)
I also tried by changing it to v3 but when i change it to v3 the map disappears.Lynettalynette
yo have to change your code slightly ...because the syntax of calling Map is change in Google Map v3...birdtheme.org/useful/v3tool.html will help you change your code according to V3..Groove
Actually sensor is not required.Loyalist
no longer required.. The sensor parameter is no longer required for the Google Maps JavaScript API. It won't prevent the Google Maps JavaScript API from working correctly, but we recommend that you remove the sensor parameter from the script element developers.google.com/maps/documentation/javascript/…Selfsealing
This is now outdated. You need to have "API key" of specyfic API that you generate from google developer console. Look at developers.google.com/maps/web and developers.google.com/maps/documentation/javascript/…Valli
As of June 22, 2016 Google Maps V3 no longer supports keyless access - https://mcmap.net/q/169273/-what-39-s-the-api-key-for-in-google-maps-api-v3Lack
Now in 2018, not only will you need API key, but also a credit card on file in GCP. Worth noting that the Map in the Chart library does not require an API key at all... in case someone needs something of a workaround. Functionality of course is a bit different.Castellated
E
18

Now you must have API key. You can generate that in google developer console. Here is LINK to the explanation.

Erl answered 2/6, 2016 at 10:48 Comment(1)
For information, I have found a workaround to continue using Google Maps API without key: #38148597Nonfulfillment
I
14

Below code No need any api to embed map on your website

?q=search here

Full url

https://maps.google.com/maps?q=chennai&t=&z=13&ie=UTF8&iwloc=&output=embed

FULL CODE

<div class="mapouter"><div class="gmap_canvas"><iframe width="600" height="500" id="gmap_canvas" src="https://maps.google.com/maps?q=chennai&t=&z=13&ie=UTF8&iwloc=&output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe></div></div>
Inclining answered 13/11, 2021 at 6:15 Comment(1)
This should be the answer, this answer saved my lifeUdometer
N
8

source

In June 2016 Google announced that they would stop supporting keyless usage, meaning any request that doesn’t include an API key or Client ID. This will go into effect on June 11 2018, and keyless access will no longer be supported

Nude answered 6/5, 2018 at 15:41 Comment(0)
C
5

You can still use free wıth iframe in google maps share button for example enter image description here

Carmoncarmona answered 20/9, 2020 at 14:12 Comment(1)
See the latest docs rb.gy/ao82p1Tuberculosis
A
4

In the below example, just replace the address provided in src with yours.

https://maps.google.com/maps?width=100%25&height=600&hl=en&q=Google, 8th Avenue, New York, NY, USA&t=&z=14&ie=UTF8&iwloc=B&output=embed

<iframe width="100%" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?width=100%25&amp;height=300&amp;hl=en&amp;q=Google, 8th Avenue, New York, NY, USA&amp;t=&amp;z=14&amp;ie=UTF8&amp;iwloc=B&amp;output=embed"></iframe>
Antwanantwerp answered 7/6, 2023 at 7:21 Comment(0)
E
3

this simple code work 100% all you need is changing 'lat','long' for address to show

<iframe src="http://maps.google.com/maps?q=25.3076008,51.4803216&z=16&output=embed" height="450" width="600"></iframe>
Eyespot answered 30/12, 2020 at 8:3 Comment(0)
H
2

Hey You can Use this insted

<iframe width="100%" height="100%" class="absolute inset-0" frameborder="0" title="map" marginheight="0" marginwidth="0" scrolling="no" src="https://maps.google.com/maps?width=100%&amp;height=600&amp;hl=en&amp;q=%C4%B0ikaneir+(Mumma's%20Bakery)&amp;ie=UTF8&amp;t=&amp;z=14&amp;iwloc=B&amp;output=embed" style="filter: scale(100) contrast(1.2) opacity(0.4);"></iframe>
Hierogram answered 30/11, 2020 at 14:48 Comment(0)
T
0

Google embedded maps are free and do not need API key documentation here:https://rb.gy/ao82p1

Tuberculosis answered 22/7 at 14:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.