Link to home
Start Free TrialLog in
Avatar of rpm
rpmFlag for United Kingdom of Great Britain and Northern Ireland

asked on

doctype tag blocks embedded Google Maps

I have a website template which was developed for me by another company. The first line of this is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

I have added some code to the site to embed Google Maps onto the site, a section of this code is as follows:

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

I was surprised when I visited this page to note that the map didn't appear.

After much experimentation, I discovered that if I deleted the doctype tag the map appeared fine, however with the doctype tag gone the layout of the site's nav bar was affected.

Can anyone telll me why the doctype tag is breaking Google Maps, and more importantly how to fix it!

Richard
Avatar of NetExpert-Warszawa
NetExpert-Warszawa
Flag of Poland image

Try the following DOCTYPE:

<!DOCTYPE html PUBLIC "-//W3C//DTD xhtml 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> 
Avatar of rpm

ASKER

Still kills the map, I'm afraid!
Could you give a link please?
Avatar of rpm

ASKER

http://www.duffields.co.uk/bfs-map.asp

The doctype tag is currentkly removed so that the map displays, but this mucks up the nav bar
You might use an old google code. See a source of http://code.google.com/intl/pl/apis/maps/documentation/examples/map-markers.html and note the difference:

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

Googles:
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA"
            type="text/javascript"></script>
...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example: Map Markers</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA"
            type="text/javascript"></script>
    <script type="text/javascript">
    
    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
 
        // Add 10 markers to the map at random locations
        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngSpan = northEast.lng() - southWest.lng();
        var latSpan = northEast.lat() - southWest.lat();
        for (var i = 0; i < 10; i++) {
          var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
                                  southWest.lng() + lngSpan * Math.random());
          map.addOverlay(new GMarker(point));
        }
      }
    }

    </script>
  </head>

  <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
  </body>
</html>

Open in new window

Avatar of rpm

ASKER

The example you have just quoted is the v2 api, I am using the v3 api
First, your website is not XHTML compliant. XHTML 1.0 Strict doctype makes no sense. However I corrected all errors and it still does not show the map.

For now you can use doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

I will further investigate the problem
ASKER CERTIFIED SOLUTION
Avatar of NetExpert-Warszawa
NetExpert-Warszawa
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rpm

ASKER

Genius! Thank you very much.

That was based on sample Google code, you'd have though they would get it right!

Richard
Avatar of rpm

ASKER

Thanks for the tip!