By yvelle on
In case anyone else is looking to do this: Once you sign up for Google Maps and get a key, you might wonder how to put a map in a node without having to put the load() and GUnload() functions in the body tag. The following code shows the method I used. Just be sure to have a lax filter so that no tags are scrapped.
** Warning: This method will probably cause problems on pages that aggregate more than one node on a page, since the javascript might be loaded more than once.**
<script
src="http://maps.google.com/maps?file=api&v=2&key="INSERT_YOUR_KEY_HERE"
type="text/javascript">
</script>
<script type="text/javascript">
function applyst() {
load();
if( window.XTRonload ) { window.XTRonload(); }
}
function savest() {
GUnload();
if( window.XTRonunload ) { window.XTRonunload(); }
}
//load handling adapted from
//http://www.brothercake.com/site/resources/scripts/onload/
if( window.addEventListener ) {
window.addEventListener( 'load', applyst, false );
window.addEventListener( 'unload', savest, false );
} else if( document.addEventListener ) {
document.addEventListener('load' , applyst, false );
document.addEventListener( 'unload', savest, false );
} else if( window.attachEvent ) {
window.attachEvent( 'onload', applyst );
window.attachEvent( 'onunload', savest );
} else {
if( window.onload ) { window.XTRonload = window.onload; }
if( window.onunload ) { window.XTRonunload = window.onunload; }
window.onload = applyst;
window.onunload = savest;
}
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(29.958839,-90.074458), 16);
map.setMapType(G_SATELLITE_MAP);
}
}
//]]>
</script>
<div id="map" style="width: 500px; height: 300px"></div>
I found these javascript functions by googling for them, so don't claim to be smart in any way.
Comments
can not show the markers and ployline with Internet Explorer
on firefox is perfected working, but no markers at all in IE?
working example
in case it is useful for anyone, I am using this code to show a simple google map in a "static page" node in drupal5 (full html input format) without extra modules.
I am using georss map but if you need different map just modify the initialize() function.
I have a function that
I have a function that creates a marker and sends some html to the infowindow for each marker to display when there is a click event. I've testing this outside of the Drupal environment with success but I'm receiving an error when I embed the code into a page node.
Could someone suggest a possible fix to this issue? Also, the map isn't shown at all in IE.