stephen stephen - 1 year ago 70
CSS Question

Google Maps API identical examples: one renders, one doesn't

Here are two jsfiddles with identical code. One is a fork from Google Maps API's documentation, no changes. The second is just copied and pasted into jsfiddle. The fork from Google renders as expected. The one I copied and pasted does not.

I used a diff checker, and it showed them as identical. What am I missing?


<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="">



// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.

function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 6
var infoWindow = new google.maps.InfoWindow({map: map});

// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude

infoWindow.setContent('Location found.');
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());

function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');


/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;

Answer Source

In your second fiddle, the JAVASCRIPT settings needs to have Load Type as No wrap - in <body>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download