Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Google Maps without a key? (from static to dynamic with URL)

I have seen that many users have asked this question, but in fact there is still no answers with examples of how to use Google Maps without a key (all the answers are references to another webpages).

I have managed to use Google Maps without the key, but I only managed to get a static map. Do you have any idea how do this dynamic?

var img = new Image();

img.src = "http://maps.googleapis.com/maps/api/staticmap?center=-32.0000343,-58.0000343&zoom=5&size=300x300&sensor=true&visualRefresh=true";

return img; //OR document.body.appendChild(img); 

Even if you simply click this link you can see the map, and if you change the "url properties" you can "edit" the map: http://maps.googleapis.com/maps/api/staticmap?center=-32.0000343,-58.0000343&zoom=5&size=300x300&sensor=true&visualRefresh=true

When I say "dynamic map" I mean to somethins like this: https://google-developers.appspot.com/maps/documentation/javascript/v2/examples/map-simple

like image 828
gal007 Avatar asked Aug 08 '13 15:08

gal007


People also ask

Can Google Maps work without API key?

In order to embed a Google Map iframe without api key add a Google Map widget from the left side panel. Then open it and add the address. This way you can embed Google Map without api key via Elementor.

How are API keys necessary for Google Maps?

A Google Maps API key is a personal code provided by Google to access Google Maps on this site. Your API key provides you with a free quota of Google Map queries. Your Google account will be automatically billed for any usage that exceeds your quota.


4 Answers

This has worked for me. I tried it on localhost. Various other solutions in stackoverflow didn't helped.

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=<?php echo urlencode($address); ?>&amp;output=embed"></iframe><br />

In this way we can generate maps dynamically based upon the address we entered in the back end.

like image 51
user46487 Avatar answered Oct 03 '22 21:10

user46487


As @geocodezip said, You're looking for Google Maps Javascript v3.

Here is simple example of using it(picked from my old answer), this doesn't need any keys.

HTML:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<div id="map-canvas"></div>

CSS:

#map-canvas {
        margin: 0;
        padding: 0;
        height: 100%;
      }

Javascript:

function initialize() {
    var myLatlng = new google.maps.LatLng(43.565529, -80.197645);
    var mapOptions = {
        zoom: 8,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

     //=====Initialise Default Marker    
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'marker'
     //=====You can even customize the icons here
    });

     //=====Initialise InfoWindow
    var infowindow = new google.maps.InfoWindow({
      content: "<B>Skyway Dr</B>"
  });

   //=====Eventlistener for InfoWindow
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

I have created a simple fiddle for your reference.

Hope you got some idea.

Since you're not interested in using keys, Beware of the limits.

Google Maps Javascript API : up to 25,000 map loads per day for each service.

This includes:

  1. a map is displayed using the Maps JavaScript API (V2 or V3) when
    loaded by a web page or application;
  2. a Street View panorama is displayed using the Maps JavaScript API (V2 or V3) by a web page or application that has not also displayed a map;
  3. a SWF that loads the Maps API for Flash is loaded by a web page or application; or
  4. a single request is made for a map image from the Static Maps API.
  5. a single request is made for a panorama image from the Street View Image API.

From your comments,

I too tried using canvas, it was not working.

 var mapCanvas = document.createElement("canvas");

But this is working good with div element.

var mapCanvas = document.createElement("div");
mapCanvas.style.width = "200px";
mapCanvas.style.height = "200px";

Updated JSFiddle

Don't forget to set width and height properties.

like image 36
Praveen Avatar answered Oct 03 '22 23:10

Praveen


I am putting an example on plunker

http://plnkr.co/T4eULTnKbWCKlABPI4pu

and the code

<!DOCTYPE html>
<html>
<body>

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=London&amp;ie=UTF8&amp;&amp;output=embed"></iframe><br />

</body>
</html>
like image 42
ackuser Avatar answered Oct 03 '22 21:10

ackuser


Use the Google Maps Javascript API v3 (lots of good examples in the documentation)

like image 23
geocodezip Avatar answered Oct 03 '22 23:10

geocodezip