最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Google Map not showing up - Stack Overflow

programmeradmin5浏览0评论

I need to implement on my php page map. 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. Can anybody help me?

<script type="text/javascript" src="javascript/jquery-1.4.3.js"></script>
<script type="text/javascript" src=""></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>

I need to implement on my php page map. 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. Can anybody help me?

<script type="text/javascript" src="javascript/jquery-1.4.3.js"></script>
<script type="text/javascript" src="http://maps.google./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>
Share Improve this question edited Oct 18, 2010 at 14:19 Matt Ball 360k102 gold badges653 silver badges720 bronze badges asked Oct 18, 2010 at 14:13 DayannaDayanna 311 silver badge2 bronze badges 4
  • How about showing the markup? Does your actual code use a Maps API key? – Matt Ball Commented Oct 18, 2010 at 14:23
  • Why not just make it into a init() function and have it load with <body onLoad=init()> ? – Mantar Commented Oct 18, 2010 at 14:24
  • I don't use Maps API key. I don't have any experience with maps,is key necessary ? – Dayanna Commented Oct 18, 2010 at 14:30
  • Version 3 of maps does not need API key – Michal Commented Oct 18, 2010 at 17:37
Add a ment  | 

5 Answers 5

Reset to default 12

Did you specify size for your 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..

I had some thing like that happen and all I had to do was use jquery pliance code. jQuery(document).ready(function($) { $(function() { // Your map code here. }); });

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.
  2. putting all your javascript inside $(document).ready() so it's only execute when the document is 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.

Hope that helps.

Check the validity of your HTML and the doctype declaration. It has been an issue on several Google Maps I've setup.

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..

Means use secure url like https

发布评论

评论列表(0)

  1. 暂无评论