// Call this function when the page has been loaded function initialize(){ var map =new google.maps.Map2(document.getElementById("map")); map.setCenter(new google.maps.LatLng(37.4419,-122.1419),13); } google.setOnLoadCallback(initialize); </script>
However when i include all this in an xslt file, i have several validation errors that i need to find a solution for... also i've never succeeded in getting google maps to output anything ...
i did it the easy way. In google maps you have the opportunity to get an embedding code (iframe way) - copy this and paste it into an xslt macro and check "Use in editor". Now you can insert this macro into an content page in tinyMCE.
Horst: true but that way you don't have the possibility to set the text inside the balloon, define markers, and all the other stuff the API allows you to customize...
Petr: how would you add the link to the javascript file in the header section if you want to use the same page templates for all content pages?
// Call this function when the page has been loaded function initialize() { var map = new google.maps.Map2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.setCenter(new google.maps.LatLng(50.86961044984257, 4.419143199920654),15);
var info='<div style="background-color: #fff; width: px; font-size: 11px; FONT-FAMILY: Verdana, Tahoma, Arial, Sans-Serif;"><B>Recytyre</B> VZW<BR>Avenue Jules Bordet 164<BR>1140 Evere<BR>Belgium<br></div>'; var point = new GLatLng(50.86961044984257, 4.419143199920654); var marker = new GMarker(point); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(info); }); map.addOverlay(marker); marker.openInfoWindowHtml(info); } google.setOnLoadCallback(initialize); </script> </asp:Content>
Inserting script with link to external source into header isn't good idea for your page load speed, if google is inaccessible :-) your page try download script and will wait for timeout.
Why you don't put content of additionalPageHead in front of your second script tag?
When we embed google maps on our websites we use this XSLT and an XML file placed in the Scripts/XML folder.
We then place the macro at the bottom of our masterpage (to increase load times) and if a GoogleMap is present (set by a document property) the javascript is loaded on the page.
XML File
We place the API Key(s) in an XML file so we can support multiple domains. This makes moving from development -> staging -> production quick and painless and it also means you can added keys for localhost or testing IP's if you need to.
The XSLT file finds the hostname and then pulls in the relevant API key.
Detailed
Get the Hostname from the Server Variables and set it to a variable of $hostname
Load the XML file we created above into a variable called $apixml
Load the correct key for the domain ($hostname) into a variable called $apikey, this contains the data within the <apicode> tag.
Then we perform a test on a attribute a document can have, so if googleMaps equals true then load the code. This is so the macro can be added on the masterpage, but only spit the Javascript code out when a GoogleMap is present. You can of course remove this if test.
If the map is present we then load the correct javascript.
The first script is the GoogleMaps JS file, in this version its using API v2, but you can change this.
The second script is the 'load' script, change this to contain the code you need for your map.
There is an issue that if the RichText content is rendered using a XSLT Macro, then the Macro contained in the RichText content does not get processed.
Try loading the content using; (replacing body for whatever is the correct alias for your richtext content).
Adding a Google Map in the content area of a webpage
I was wondering how you would approach adding a google map to the content area of a page?
steps involved:
-Adding a javascript tag to the header section of the page where it is used (with the google maps api key)
- creating a div with width and height defining the container for the map:
-loading additional javascript
However when i include all this in an xslt file, i have several validation errors that i need to find a solution for... also i've never succeeded in getting google maps to output anything ...
All help is very much appreciated!
Hi Rik,
i did it the easy way.
In google maps you have the opportunity to get an embedding code (iframe way) - copy this and paste it into an xslt macro and check "Use in editor".
Now you can insert this macro into an content page in tinyMCE.
/horst
* add script into separate .js file and add link to it
* put script into cdata section in xslt
Horst: true but that way you don't have the possibility to set the text inside the balloon, define markers, and all the other stuff the API allows you to customize...
Petr: how would you add the link to the javascript file in the header section if you want to use the same page templates for all content pages?
This is my temporary solution that embeds it into a page template (but i'd still like to be able to embed it into the content area itself...)
Hi,
Inserting script with link to external source into header isn't good idea for your page load speed, if google is inaccessible :-) your page try download script and will wait for timeout.
Why you don't put content of additionalPageHead in front of your second script tag?
Maybe you should look at http://clientdependency.codeplex.com/ which is for automating including scripts, minifiiing it etc.
Petr
Hi,
When we embed google maps on our websites we use this XSLT and an XML file placed in the Scripts/XML folder.
We then place the macro at the bottom of our masterpage (to increase load times) and if a GoogleMap is present (set by a document property) the javascript is loaded on the page.
XML File
We place the API Key(s) in an XML file so we can support multiple domains. This makes moving from development -> staging -> production quick and painless and it also means you can added keys for localhost or testing IP's if you need to.
XSLT File
The XSLT file finds the hostname and then pulls in the relevant API key.
Detailed
This is so the macro can be added on the masterpage, but only spit the Javascript code out when a GoogleMap is present.
You can of course remove this if test.
Hope this helps! :)
Laurie
@Petr - that looks really sweet! (: thanks, i'll have a play with that next week.
Maybe you should look at http://clientdependency.codeplex.com/ which is for automating including scripts, minifiiing it etc.
why wouldn't you just use one of the many google maps packages found in the projects section of this website?
Horst - I've tried your suggestion as I'm happy to use the iframe method but I have a problem:
When I visualise my xslt, I can see the map just fine, it's all good, but when I drop the macro into a page in tinyMCE, it doesn't render...
The rendered markup is just
<?UMBRACO_MACRO macroAlias="GoogleMap" />
Am I missing something here?
There is an issue that if the RichText content is rendered using a XSLT Macro, then the Macro contained in the RichText content does not get processed.
Try loading the content using; (replacing body for whatever is the correct alias for your richtext content).
Hope that helps, Laurie
<?UMBRACO_MACRO /> is the old format for v3, you need to use <umbraco:Macro Alias="GoogleMap" runat="server" /> in v4.
Hope this helps.
Benjamin
Laurie, you're a genius, thanks very much : )
No worries! Its always something simple!
Hopefully this will be fixed soon ;) /Laurie
is working on a reply...