<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cheap Website Design Blog &#187; Tutorials</title>
	<atom:link href="http://www.coolcreation.co.uk/website-design-blog/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coolcreation.co.uk/website-design-blog</link>
	<description>Website Design &#38; Development</description>
	<lastBuildDate>Wed, 08 Feb 2012 08:42:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Google Map With Auto Info Window</title>
		<link>http://www.coolcreation.co.uk/website-design-blog/google-map-with-auto-info-window/</link>
		<comments>http://www.coolcreation.co.uk/website-design-blog/google-map-with-auto-info-window/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 12:20:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.coolcreation.co.uk/website-design-blog/?p=98</guid>
		<description><![CDATA[There are many guides out the there that explain in detail how to create a google map, however I struggled to find one that would show you how to create a Google map for your webpage, create a marker on &#8230; <a href="http://www.coolcreation.co.uk/website-design-blog/google-map-with-auto-info-window/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/apis/maps/signup.html" target="_blank"><img class="alignright size-medium wp-image-103" title="google-maps-tutorial" src="http://www.coolcreation.co.uk/website-design-blog/wp-content/uploads/2008/08/google-maps-tutorial-300x228.jpg" alt="" width="300" height="228" /></a>There are many guides out the there that explain in detail how to create a google map, however I struggled to find one that would show you how to create a Google map for your webpage, create a marker on the map, create an info window and make that window centre on the page and open automatically on page load. After doing all this I also wanted the map to load in satellite view as a default too.</p>
<p>The biggest flaw I found was in opening the html info window of the map automatically,  I managed to get this working in Firfox, however in the latest version of IE I simply received a Javascript error and the map would not load.</p>
<p>This tutorial will show you how to;</p>
<p>Create a Google map<br />
get co-ordinates for your location quickly<br />
Place a marker and info window on the map<br />
Open the widow automatically<br />
Load the map in Satellite mode as default</p>
<p><strong>Lets start by obtaining your Maps API key from Google<br />
</strong></p>
<p>Go <a href="http://code.google.com/apis/maps/signup.html" target="_blank">here </a>and sign up for a Google maps api Key <a href="http://code.google.com/apis/maps/signup.html" target="_blank">http://code.google.com/apis/maps/signup.html</a></p>
<p>Once completed you will be provided with a Key that is unique to your domain name, copy this and put it somewhere safe for a few moments.</p>
<p>Open up your webpage in a HTML editor and place this line into the head section of your page.<br />
<code>&lt;<span class="start-tag">script</span><span class="attribute-name"> src</span>=<span class="attribute-value">"http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=ABQIAAAAoeym2RwBy_aygGSCU-AxjRQ7qZ61VBL5U7OYDjSzrhfRKw1GIxSNsyhPasBJnueyUp-gcfonzwIm1Q" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/javascript"</span>&gt;&lt;/<span class="end-tag">script</span>&gt;</code><br />
Where it says key= be sure to include your key instead of the one seen here.</p>
<p><strong>Now create the div that will contain your map</strong></p>
<p>If you have not already done so, now is the time to create the area that you want the map to go in. Create a div in your html page with the ID map, so <code>&lt;div id="map"&gt;</code></p>
<p>In your style sheet, lets setup how you want it to look, for the sake of this tutorial, I will simply create a simple div;</p>
<p><code>#map { width:500px; height:500px }</code></p>
<p><strong>Lets create the actual map</strong></p>
<p>All of this code should be added in the head section of your website.</p>
<p>The first thing we are going to add is the event that will trigger the info window to open on page load. If you would prefer just to show your marker and not have the window open on load then ignore this section.<br />
<code>&lt;<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text/javascript"</span>&gt;<br />
function createMarker(point,html) {<br />
var marker = new GMarker(point);<br />
GEvent.addListener(marker, "click", function() {<br />
marker.openInfoWindowHtml(html);<br />
});<br />
return marker;<br />
}<br />
&lt;/script&gt;</code></p>
<p>Now we need to initialise the map and make it target the div you have just created, note: if your div has a different id then sipply chang &#8220;map&#8221; in the script below to your div.<br />
<code> function initialize() {<br />
if (GBrowserIsCompatible()) {<br />
var map = new GMap2(document.getElementById("map"));<br />
map.addControl(new GMapTypeControl());<br />
map.setCenter(new GLatLng(43.298344, 5.383221), 13);<br />
}<br />
}</code></p>
<p>This map is now centered over somewhere in France, you are probably thinking at this point, how the hell do I get the co-ordinates for where I want the map to show. You will be pleased to know that it is simple.</p>
<p>Go to <a href="http://maps.google.com/" target="_blank">http://maps.google.com/</a> and enter your location, lets choose Marseilles in France. click search maps.</p>
<p>Once the map has loaded enter this line of code into your browser address bar and press enter</p>
<p><code>javascript:void(prompt('',gApplication.getMap().getCenter()));</code></p>
<p>You should now have the co-ordinates open in a popup window ready for you use. Where in the code we have this</p>
<p><code>map.setCenter(new GLatLng(43.298344, 5.383221), 13);</code></p>
<p>Simply replace my co-ordinates with your own. We have now set the area that the map will show.</p>
<p><strong>And now for your marker</strong></p>
<p>We need to use the script to create a marker point, we also do this using co-ordinates, for the sake of this tutorial and to keep things simple, lets use the same co-ordinates that the map is located in.<br />
<code>var point = new GLatLng(43.298344, 5.383221);<br />
var marker = createMarker(point)<br />
map.addOverlay(marker);</code></p>
<p>Lets add your info window. This can contain HTML and you can even include images<br />
<code>map.openInfoWindowHtml(map.getCenter(),("&lt;b&gt;A Title&lt;/b&gt;&lt;br&gt;Text about France"));</code></p>
<p>Put it all together and you should have something that looks like this;<br />
<code>&lt;script type="text/javascript"&gt;<br />
function createMarker(point,html) {<br />
var marker = new GMarker(point);<br />
GEvent.addListener(marker, "click", function() {<br />
marker.openInfoWindowHtml(html);<br />
});<br />
return marker;<br />
}<br />
function initialize() {<br />
if (GBrowserIsCompatible()) {<br />
var map = new GMap2(document.getElementById("map"));<br />
map.addControl(new GMapTypeControl());<br />
map.setCenter(new GLatLng(43.298344, 5.383221), 13);<br />
map.openInfoWindowHtml(map.getCenter(),("&lt;b&gt;A Title&lt;/b&gt;&lt;br&gt;Text about France"));<br />
var point = new GLatLng(43.298344, 5.383221);<br />
var marker = createMarker(point)<br />
map.addOverlay(marker);<br />
}<br />
}<br />
&lt;/script&gt;</code></p>
<p>There is one final thing you need to do and that is initiate the map load when the page is viewed by someone, we do this by adding this piece of code in place of your body tag;<br />
<code>&lt;<span class="start-tag">body</span><span class="attribute-name"> onload</span>=<span class="attribute-value">"initialize()" </span><span class="attribute-name">onunload</span>=<span class="attribute-value">"GUnload()"</span>&gt;</code></p>
<p><strong>The extras</strong></p>
<p>I personally prefer maps to open in Satellite view by default and also with smaller controls on the map, we do this by adding the following to the script;<br />
<code>map.setMapType(G_SATELLITE_MAP);<br />
map.addControl(new GSmallMapControl());</code></p>
<p>And thats it! everything is now complete and if you want the same code as me, it should look something like this;</p>
<p><code><br />
&lt;script type="text/javascript"&gt;<br />
function createMarker(point,html) {<br />
var marker = new GMarker(point);<br />
GEvent.addListener(marker, "click", function() {<br />
marker.openInfoWindowHtml(html);<br />
});<br />
return marker;<br />
}<br />
function initialize() {<br />
if (GBrowserIsCompatible()) {<br />
var map = new GMap2(document.getElementById("map"));<br />
map.addControl(new GSmallMapControl());<br />
map.addControl(new GMapTypeControl());<br />
map.setCenter(new GLatLng(43.298344, 5.383221), 13);<br />
map.setMapType(G_SATELLITE_MAP);<br />
map.openInfoWindowHtml(map.getCenter(),("&lt;b&gt;A Title&lt;/b&gt;<br />
text about France"));<br />
var point = new GLatLng(43.298344, 5.383221);<br />
var marker = createMarker(point)<br />
map.addOverlay(marker);<br />
}<br />
}<br />
&lt;/script&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.coolcreation.co.uk/website-design-blog/google-map-with-auto-info-window/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

