views:

70

answers:

4

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.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
<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>
A: 

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

See this

bpeterson76
It's valid, no errors but still it doesn't show .
Dayanna
+4  A: 

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

Michal
I good way to test this is to comment out the JavaScript and make the background of the div obvious (say, bright red). If the red rectangle (where you want the map) is in the right place, then at least your HTML/CSS is correct.
Jared Updike
+1  A: 

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.

Abel Tamayo
+1  A: 

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

Vaughn