IE and Disappearing Google Maps API Routes
I ran into this one earlier today. Essentially, you use the Google Maps API’s GDirections object to load some directions into your map. Occasionally, without warning or any pattern I can see, the little blue-ish route polyline will begin disappearing in IE 6 and IE 7. There seems to be no rhyme or reason to it, although I suspect that it has to do with DOM modifications after the map redraws.
Speculation aside, here’s a fix that I dug out of the Google Maps API Group. Make sure your document is using a valid DOCTYPE (duh) and then add the following XML namespacing to your HTML tag:
<html xmlns=”http://www.w3.org/1999/xhtml” xmlns:v=”urn:schemas-
microsoft-com:vml”>
</html>
I didn’t have access to that part of the document as I’m working in a CMS, but found that this JavaScript version worked:
var el = document.getElementsByTagName('head')[0];
el.setAttribute('xmlns','http://www.w3.org/1999/xhtml');
el.setAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
That should fix the problem. However, it may pop-up again if you clear the map results and any overlays you have, and plot points on that same map again. Really odd. Does Google clobber that namespace at some point, after centering or drawing a map? I haven’t been able to test to find out. My only thought would be to set those attributes after every redraw or map load, but that could be a bit of overkill.
Still, if you can promise only a single load of a set of directions, the above should save you. Here’s the Google Groups thread for posterity.