?
Solved

doctype tag blocks embedded Google Maps

Posted on 2010-03-25
11
Medium Priority
?
594 Views
Last Modified: 2012-05-09
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
0
Comment
Question by:rpm
  • 6
  • 5
11 Comments
 
LVL 10

Expert Comment

by:NetExpert-Warszawa
ID: 28577360
Try the following DOCTYPE:

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

Author Comment

by:rpm
ID: 28578575
Still kills the map, I'm afraid!
0
 
LVL 10

Expert Comment

by:NetExpert-Warszawa
ID: 28581073
Could you give a link please?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 1

Author Comment

by:rpm
ID: 28581388
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
0
 
LVL 10

Expert Comment

by:NetExpert-Warszawa
ID: 28581649
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

0
 
LVL 1

Author Comment

by:rpm
ID: 28581779
The example you have just quoted is the v2 api, I am using the v3 api
0
 
LVL 10

Expert Comment

by:NetExpert-Warszawa
ID: 28667706
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
0
 
LVL 10

Accepted Solution

by:
NetExpert-Warszawa earned 2000 total points
ID: 28668320
I believe this is the error:
<div id="map_canvas" style="width:600; height:500"></div>

You wanted to use:
<div id="map_canvas" style="width:600px; height:500px"></div>

Could you verify it please?
0
 
LVL 1

Author Closing Comment

by:rpm
ID: 31707045
Genius! Thank you very much.

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

Richard
0
 
LVL 10

Expert Comment

by:NetExpert-Warszawa
ID: 28668743
0
 
LVL 1

Author Comment

by:rpm
ID: 28668825
Thanks for the tip!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question