bencarter78 bencarter78 - 1 year ago 169
Javascript Question

Google Maps API showing blank map

I'm sure this is a basic problem but I've hit my head against the wall too many times now, so hopefully someone will take pity on me!

I have the following example but all it does is show a grayed out box, no map at all. Can anyone tell me why?

I've checked that I'm actually returning a result and it seems to be working fine.

<!DOCTYPE html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

html, body, #map-canvas {margin: 0;padding: 0;height: 100%;}
<script src=""></script>
var geocoder;
var map;

function initialize()
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': "England"}, function(results, status)
if (status == google.maps.GeocoderStatus.OK)
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(results[0].geometry.location),
mapTypeId: google.maps.MapTypeId.ROADMAP

// Let's draw the map
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

alert("Geocode was not successful for the following reason: " + status);


<body onload="">
<div id="map-canvas" style="width: 320px; height: 480px;"></div>

Answer Source

results[0].geometry.location is already a latLng object so you can just say:

center: results[0].geometry.location

Find the working fiddle here :

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