Dayanna
Dayanna

Reputation: 31

Google Map not showing up

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"></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>

Upvotes: 3

Views: 4803

Answers (5)

safi khan
safi khan

Reputation: 1

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.

Means use secure url like https

Upvotes: 0

webLacky3rdClass
webLacky3rdClass

Reputation: 649

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. }); });

Upvotes: 4

Abel Tamayo
Abel Tamayo

Reputation: 165

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.

Upvotes: 1

Michal
Michal

Reputation: 13649

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

Upvotes: 12

bpeterson76
bpeterson76

Reputation: 12870

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

See this

Upvotes: 0

Related Questions