Google Maps API显示空白地图 [英] Google Maps API showing blank map
本文介绍了Google Maps API显示空白地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我确信这是一个基本问题,但我已经多次撞到墙上,所以希望有人会怜惜我!
我有下面的例子,但它所做的只是显示一个灰色的框,根本没有地图。任何人都可以告诉我为什么?
我检查过我实际上正在返回一个结果,它似乎工作正常。
<!DOCTYPE html>
< html>
< head>
< meta charset =utf-8>
< meta http-equiv =X-UA-Compatiblecontent =IE = edge>
< title>< / title>
< meta name =descriptioncontent =>
< meta name =viewportcontent =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;
函数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
}
//让我们画出地图
map = new google.maps.Map(document.getElementById(map-canvas),mapOptions);
{
alert(由于以下原因,地理编码不成功:+状态);
}
}) ;
}
initialize();
< / script>
< / head>
< body onload =>
< div id =map-canvasstyle =width:320px; height:480px;>< / div>
< / body>
< / html>
解决方案
results [0]。 geometry.location
已经是latLng对象,因此您可以说:
center:results [0 ] .geometry.location
在这里找到工作小提琴: http://jsfiddle.net/87z9K/
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>
<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>
解决方案
results[0].geometry.location
is already a latLng object so you can just say:
center: results[0].geometry.location
Find the working fiddle here : http://jsfiddle.net/87z9K/
这篇关于Google Maps API显示空白地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文