Google地图不会显示 [英] Google map does not appear

查看:105
本文介绍了Google地图不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循Google的介绍性教程地图,但由于某种原因,地图没有出现在我的网页上。相关的HTML / CSS / JS是:

 <!DOCTYPE html> 
< html>
< head>
< meta name =layoutcontent =main/>

< script type =text / javascript
src =http://maps.googleapis.com/maps/api/js?sensor=false>
< / script>
< script type =text / javascript>
函数initialize(){
var latlng = new google.maps.LatLng(-34.397,150.644);
var myOptions = {
zoom:8,
center:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(map_canvas),
myOptions);
}

< / script>
< / head>

< body onload =initialize()>
< div id =map_canvasstyle =width:400px; height:400px>< / div>
< / body>

< / html>

地图不会出现在 map_canvas div。



更新



我更改了页面,以便它不使用JQuery加载地图。它现在使用与本教程中完全相同的JS,但仍然没有出现映射。

解决方案

有3个问题(1)在< script type =text / javascript> function initialize(){前添加以下行: / code>

 < script type =text / javascriptsrc =http://maps.googleapis的.com /地图/ API / JS传感器=假>?; 
< / script>

这是您的答案的帖子,但它不在您的文件中 http://www.iol.ie/~murtaghd/map/map.htm 。 (2)你需要调用 initalize()(同样的:它在你的文章中,而不是在代码中):

 < body onload =initialize();> 

(3)设置画布的大小以显示地图(再次:它位于您的发布,但不在代码中)。

 < div id =map_canvasstyle =width:500px; height :300像素>< / DIV> 

您可以在 jsfiddle


I'm following the introductory tutorial for Google Maps, but for some reason the map is not appearing on my webpage. The relevant HTML/CSS/JS is:

<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>

    <script type="text/javascript"
        src="http://maps.googleapis.com/maps/api/js?sensor=false">
    </script>
    <script type="text/javascript">
      function initialize() {
        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
          zoom: 8,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            myOptions);
      }

    </script>
</head>

<body onload="initialize()">
  <div id="map_canvas" style="width: 400px; height: 400px"></div>
</body>

</html>

The map does not appear within the map_canvas div.

Update

I've changed the page so that it doesn't use JQuery to load the map. It now uses exactly the same JS as in the tutorial, but still the map does not appear.

解决方案

There are 3 problems with your code:

(1) add the following lines before <script type="text/javascript">function initialize() {

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script> 

This is in the post of your answer, but it is not in your file http://www.iol.ie/~murtaghd/map/map.htm.

(2) You need to call initalize() (again: it is in your post, but not in the code):

<body onload="initialize();">

(3) Set the size of the canvas to get the map displayed (again: it is in your post, but not in the code). Afterwards you can change the size as you like.

<div id="map_canvas" style="width:500px; height:300px"></div>

You can see the site running on jsfiddle.

这篇关于Google地图不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆