我相信这是一个基本问题,但我已经撞了太多次墙头,所以希望有人能同情我!
我有以下示例,但它只显示一个灰色的框,没有地图。有人能告诉我为什么吗?
我已经检查过我实际上是否返回了结果,而且似乎运行良好。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html, body, #map-canvas {margin: 0;padding: 0;height: 100%;}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<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);
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
}
initialize();
</script>
</head>
<body onload="">
<div id="map-canvas" style="width: 320px; height: 480px;"></div>
</body>
</html>
code
var options = { zoom: 6, center: new google.maps.LatLng(-2.633333, 37.233334), mapTypeId: google.maps.MapTypeId.TERRAIN, mapTypeControl: false };// 初始化地图 var map = new google.maps.Map(document.getElementById('map_canvas'), options);
code
- Anuragwindow.dispatchEvent(new Event('resize'));
。尽管最佳方法可能包括IE等的替代方案。 - Bob Stein