简体   繁体   English

Google地图未显示

[英]Google Map not showing up

I need to implement on my php page map. 我需要在我的php页面地图上实现。 I have container <div id="map"></div> which is inside other div, and I put this code inside <head> tag but it doesn't show at all. 我有容器<div id="map"></div> ,它位于其他div中,我将此代码放在<head>标记内,但它根本不显示。 Can anybody help me? 有谁能够帮助我?

<script type="text/javascript" src="javascript/jquery-1.4.3.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
(function() {
    window.onload = function() {
        var mapDiv = document.getElementById('map');
        var latlng = new google.maps.LatLng(37.09, -95.71);
        var options = {
            center: latlng,
            zoom: 4,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(mapDiv, options);
    }
})();​
</script>

Did you specify size for your div? 你有没有为你的div指定大小? eg: 例如:

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

If this doesn't work you might have to post a snippet of your HTML and CSS.. 如果这不起作用,您可能需要发布HTML和CSS的片段。

I had some thing like that happen and all I had to do was use jquery compliance code. 我有类似的事情发生,我所要做的就是使用jquery合规性代码。 jQuery(document).ready(function($) { $(function() { // Your map code here. }); }); jQuery(document).ready(function($){$(function(){//这里的地图代码。});});

Your code does work for me even though the last line, when you close that anonymous function, gave me an error like you were using some illegal character, so I had to retype it. 你的代码对我有用,即使最后一行,当你关闭匿名函数时,给了我一个错误,就像你使用了一些非法字符一样,所以我不得不重新输入它。 Once I did, it worked perfectly showing a road map of all of the United States. 有一次,它完美地显示了所有美国的路线图。 Other than that possible illegal character you could also try: 除了可能的非法角色,您还可以尝试:

  1. giving your #map element a height and width or else it won't be visible. 给你的#map元素一个高度和宽度,否则它将不可见。
  2. putting all your javascript inside $(document).ready() so it's only execute when the document is ready. 将所有javascript放在$(document).ready()中,这样它只在文档准备好时执行。
  3. you say that you include your scripts in the head tag of your document, but maybe you should try putting them at the end of your body to speed up loading. 你说你将脚本包含在文档的head标签中,但也许你应该尝试将它们放在身体末端以加快加载速度。

Hope that helps. 希望有所帮助。

Check the validity of your HTML and the doctype declaration. 检查HTML和doctype声明的有效性。 It has been an issue on several Google Maps I've setup. 这是我设置的几个Google地图上的一个问题。

See this 看到这个

If any one using google map code from javascript or jquery or any language, He/She should use for local host https://localhost/test/ or in server https://example.com . 如果任何人使用来自javascript或jquery或任何语言的谷歌地图代码,他/她应该使用本地主机https:// localhost / test /或服务器https://example.com

Means use secure url like https 意味着像https一样使用安全网址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM