XHTML doctype breaks API v3

614 views
Skip to first unread message

kbs1

unread,
Sep 10, 2009, 7:26:14 PM9/10/09
to Google Maps JavaScript API v3
Hello, I have never developed for google maps api until now. For 4
hours now I have been fiddling with the map not displaying at all on a
website, that I am writing.

See the problem directly:
http://new.mediamenu.sk/maps_test.html

Now what is the file? It is an example from the official website, ONLY
customized to use the XHTML doctype. That's right, only two top lines
are different.

The map does not display at all.

Facts that I have elaborated right now:
- it does not matter if you use the strict or transitional doctype
- it does not matter if you serve the page using text/html or
application/xhtml+xml
- no combination of meta tags or script elements would solve this
problem
- it does not matter if you wrap the map-creating JS code in <![CDATA
[ and ]]>

I also looked on the source of http://maps.google.com/maps/api/js?sensor=false.
It tries to fetch the main map script by calling getScript("http://
maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/main.js");

- getScript uses document.write, which I think is impossible to use in
XHTML.
- loading http://maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/main.js
directly via another script tag does not help.
- loading customized version of http://maps.google.com/maps/api/js?sensor=false
with commented out line getScript and after that loading
http://maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/main.js via
another script tag does not help.

Once I've seen the code of http://maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/main.js,
I gave up and now I am asking you guys for help :(

I've almost lost my hair trying to figure this out, google please help
me.

Thanks!
Viliam Kubis

skaffman

unread,
Sep 11, 2009, 5:30:51 AM9/11/09
to Google Maps JavaScript API v3
I posted a message a few days ago about this, although in my case it
was the XHTML MobileProfile doctype that caused the problem. From your
message, it seems like the problem is much wider than that, and all
XHTML doctypes break the API.


On Sep 11, 12:26 am, kbs1 <viliam.ku...@gmail.com> wrote:
> Hello, I have never developed for google maps api until now. For 4
> hours now I have been fiddling with the map not displaying at all on a
> website, that I am writing.
>
> See the problem directly:http://new.mediamenu.sk/maps_test.html
>
> Now what is the file? It is an example from the official website, ONLY
> customized to use the XHTML doctype. That's right, only two top lines
> are different.
>
> The map does not display at all.
>
> Facts that I have elaborated right now:
> - it does not matter if you use the strict or transitional doctype
> - it does not matter if you serve the page using text/html or
> application/xhtml+xml
> - no combination of meta tags or script elements would solve this
> problem
> - it does not matter if you wrap the map-creating JS code in <![CDATA
> [ and ]]>
>
> I also looked on the source ofhttp://maps.google.com/maps/api/js?sensor=false.
> It tries to fetch the main map script by calling getScript("http://
> maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/main.js");
>
> - getScript uses document.write, which I think is impossible to use in
> XHTML.
> - loadinghttp://maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/main.js
> directly via another script tag does not help.
> - loading customized version ofhttp://maps.google.com/maps/api/js?sensor=false
> with commented out line getScript and after that loadinghttp://maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/main.jsvia
> another script tag does not help.
>
> Once I've seen the code ofhttp://maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/main.js,

Esa

unread,
Sep 11, 2009, 6:37:18 AM9/11/09
to Google Maps JavaScript API v3

kbs1

unread,
Sep 11, 2009, 4:06:28 PM9/11/09
to Google Maps JavaScript API v3
Thanks, Esa! This solved the problem half-way. At least I am now able
to see the map in a document with XHTML doctype.

However the map still does not work if you serve your document with
Content-Type of application/xhtml+xml.

See the test page at http://new.mediamenu.sk/maps_test.php

It's the same page only served with another content-type.
Unfortunately the project I am working on must be served using
application/xhtml+xml.

It seems that the maps code does not initialize at all, because opera
reports "type mismatch" error on line 5 of inline script which is

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);

Is this a bug with google maps?

Thanks!!

On Sep 11, 12:37 pm, Esa <esa.ilm...@gmail.com> wrote:
> Try defining height of the parent elements:
>
> html, body {height: 100%}
>
> http://groups.google.com/group/google-maps-js-api-v3/browse_thread/th...

kbs1

unread,
Sep 11, 2009, 7:52:54 PM9/11/09
to Google Maps JavaScript API v3
...just tried implementing document.write hack from site
http://ejohn.org/blog/xhtml-documentwrite-and-adsense/ but no luck,
map still does not show up :(

kbs1

unread,
Sep 11, 2009, 8:17:13 PM9/11/09
to Google Maps JavaScript API v3
SUCCESS!!!!

With this wonderful script made by Mr. Weston Ruter to emulate
document.write in XHTML (http://shepherd-interactive.googlecode.com/
svn/trunk/xhtml-document-write/xhtml-document-write.js), the map
finally shows up!! I have not updated the test page, but it works. I
thought from the beginning that document.write is the problem.

Maybe in future versions you could try to avoid using document.write,
that would be great! Or at least post some notice on the front page so
that people know how to get the maps working.

Cheers!

pamela (Google Employee)

unread,
Sep 11, 2009, 8:20:59 PM9/11/09
to google-map...@googlegroups.com
We do offer a way of loading the Maps API dynamically (via script
append instead of document.write), though I think it may not be in the
documentation.

See this demo:
http://gmaps-samples-v3.googlecode.com/svn/trunk/callback/callback_delayed.html

Is that what you were looking for?

- pamela

Esa

unread,
Sep 11, 2009, 8:33:13 PM9/11/09
to Google Maps JavaScript API v3


On Sep 12, 3:20 am, "pamela (Google Employee)" <pamela...@gmail.com>
wrote:
> We do offer a way of loading the Maps API dynamically (via script
> append instead of document.write), though I think it may not be in the
> documentation.
>
> See this demo:http://gmaps-samples-v3.googlecode.com/svn/trunk/callback/callback_de...
>

That demo page tries to call

google.maps.loadScripts();

by load event of the appended script. That function is not found and
an error is thrown with FF.

pamela (Google Employee)

unread,
Sep 11, 2009, 8:42:59 PM9/11/09
to google-map...@googlegroups.com
Thanks for seeing that, Esa. We used to require developers to call
that function, but we now call it ourselves, internally, so that
developers don't need to.

I have just updated the samples and you can see that it is an easy
technique to use.

- pamela

kbs1

unread,
Sep 12, 2009, 7:54:20 AM9/12/09
to Google Maps JavaScript API v3
Hello Pamela, thanks for your fast reply. The method you have
mentioned does actually work perfect. I have updated the test page at
http://new.mediamenu.sk/maps_test.php so that anybody can verify that,
the page is pure XHTML served as application/xhtml+xml. I guess this
is the right way to do it instead of the dirty document.write XHTML
hack.

You should update the documentation so that people know this method
even exist. I have spent hours of researching and searching the web,
but the "callback" parameter when loading the script is not mentioned
anywhere, at least not in api V3 documentation.

Thanks & have a nice day

On 12. Sep., 02:20 h., "pamela (Google Employee)"
<pamela...@gmail.com> wrote:
> We do offer a way of loading the Maps API dynamically (via script
> append instead of document.write), though I think it may not be in the
> documentation.
>
> See this demo:http://gmaps-samples-v3.googlecode.com/svn/trunk/callback/callback_de...

pamela (Google Employee)

unread,
Sep 13, 2009, 5:12:07 AM9/13/09
to google-map...@googlegroups.com
Ah, I did find where we documented it here:
http://code.google.com/apis/maps/faq.html#loadasync

But the FAQ is typically the last place checked. We'll work on getting
that into the core documentation for v3.

- pamela
Reply all
Reply to author
Forward
0 new messages