Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
103
rated 0 times [  106] [ 3]  / answers: 1 / hits: 71736  / 11 Years ago, tue, november 5, 2013, 12:00:00

I wanted to try out a sample demo of implementing Gmaps v3 and tried out this example from Google's documentation, but there is no output , the page just loads for a few seconds and then blank, no output.



<!DOCTYPE html>
<html lang = en>
<head>
<style type=text/css>
html{height: 100%}
body{height: 100%; margin: 0; padding: 0}
#map-canvas{height: 100%}
</style>
<title>GMaps Demo</title>
<script src = https://maps.googleapis.com/maps/api/js?
key=${API_KEY}&sensor=false>
</script>
<script>
function initialize(){
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = google.maps.Map(
document.getElementById(map-canvas),
mapOptions);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id = map-canvas>
</div>
</body>
</html>

More From » google-maps

 Answers
70

First of all: Google Maps 3 does not need an api key anymore, so you are fine with



https://maps.googleapis.com/maps/api/js?sensor=false


as an URL.



(As Jeff Hoye pointed out, as of June 22, 2016, an API Key is required again.)



And then you forgot the new in this line:



var map = new google.maps.Map(document.getElementById(map-canvas), mapOptions);



With those changes your map will be displayed.


[#74504] Monday, November 4, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elaine

Total Points: 628
Total Questions: 111
Total Answers: 104

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
;