<?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>Kaweb</title>
	<atom:link href="http://www.kaweb.co.uk/tag/geocode/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kaweb.co.uk</link>
	<description>Web Design Birmingham</description>
	<lastBuildDate>Sun, 06 Nov 2011 16:24:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Property Mapping</title>
		<link>http://www.kaweb.co.uk/blog/property-mapping/</link>
		<comments>http://www.kaweb.co.uk/blog/property-mapping/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 13:19:06 +0000</pubDate>
		<dc:creator>paul.ingram</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[agent]]></category>
		<category><![CDATA[estate]]></category>
		<category><![CDATA[geocode]]></category>
		<category><![CDATA[mapping]]></category>
		<category><![CDATA[property]]></category>

		<guid isPermaLink="false">http://www.kaweb.co.uk/?p=259</guid>
		<description><![CDATA[Due to there being no need for a commercial license, and the superior amount of support available, Kaweb plumped for Google Maps for our new service, mappr.]]></description>
			<content:encoded><![CDATA[<p>When it comes to online mapping, and in many other web applications, Google is by far the biggest player. Inevitably, there are alternatives out there &#8211; most notably <a title="Microsoft Virtual Earth" href="http://msdn.microsoft.com/en-us/virtualearth/default.aspx">Microsoft’s Virtual Earth</a>, which features a startlingly good birds eye view whereby the land is viewable at an angle from just above the buildings, allowing one an impressive 3D view of an area.</p>

<p>However, due to there being no need for a commercial license, and the superior amount of support available (including the excellent <a title="Google Maps API tutorials" href="http://econym.org.uk/gmap/">Mike Williams tutorials</a>), we at Kaweb plumped for Google Maps for our new service, <a title="mappr - property mapping form Kaweb" href="http://www.kaweb.co.uk/news/mappr-the-new-mapping-service-from-kaweb/">mappr</a>.</p>

<p>The service will be primarily used to plot estate agents’ properties on a map, allowing potential homebuyers to see what real estate is available in a given area. The aims of the project were:</p>
<ul>
<li>Automatic geocoding from postcode data in order to plot the markers</li>
<li>Summarise property info in a panel rather than the default info bubble</li>
<li>Real-time updating on map movement or criteria change</li>
</ul>
<h3>Automatic Geocoding</h3>
<p>Geocoding is simply the process of turning an address into a set of latitude-longtude co-ordinates. In the case of property, we intended to essentially convert the postcode into co-ordinates, to be stored in the database. However, due to the Royal Mail’s copyright, this requires payment. There are attempts at an <a title="Open UK postcode database" href="http://www.freethepostcode.org/">open database</a>, though this remains incomplete.</p>

<p>Google do offer a free <a title="Geocoding via Google Maps" href="http://googlemapsapi.blogspot.com/2007/07/uk-geocoding-now-available-in-maps-api.html">geocoding service</a> via their Maps API but the UK results are somewhat variable, over a mile off in some instances. The solution was somewhat surprising &#8211; simply use another of Google’s APIs – the AJAX Search API, in Local Search mode. Using the <a title="Google AJAX API (REST interface)" href="http://code.google.com/apis/ajaxsearch/documentation/#fonje">REST interface</a>, we were able to retrieve accurate JSON-encoded data that was simply parsed and stored. Example PHP code:</p>

<code>$postcode = 'WS13 6TJ';
$url = "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&amp;q=".urlencode($postcode);</code>
<code>// Note how referrer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.kaweb.co.uk/");
$body = curl_exec($ch);
curl_close($ch);</code>
<code>// Now, process the JSON string
$json = json_decode($body);</code>
<code>// Latitude: $json-&gt;responseData-&gt;results[0]-&gt;lat
// Longitude: $json-&gt;responseData-&gt;results[0]-&gt;lng
</code>
<h3>Display summary panel on click</h3>
<p>Rather than use the native information bubble <a href="http://code.google.com/apis/maps/documentation/reference.html#GInfoWindow">GInfoWindow</a>, which we felt was rather uninspiring, we wanted to display a semi-transparent panel overlaid on the map. The key to this was to inject the HTML into the map&#8217;s holding div once the map content had been loaded. For example, using the markup below as the document&#8217;s starting HTML would mean anything within the &#8220;map&#8221; div (i.e. mappr_panel) gets overlaid when the map is rendered.</p>

<code>&lt;div id="map"&gt;&lt;div id="mappr_panel"&gt;Panel Contents&lt;/div&gt;&lt;div&gt;</code>

<p>Instead, we used our Javascript framework of choice, <a title="jQuery" href="http://jquery.com/">jQuery</a>, in conjunction with a marker click listener.</p>

<code>// Create a marker called our_marker here
Event.addListener(our_marker, 'click', function(){
var contents = 'Marker ID: ' + our_marker.id;
show_panel(contents);</code><code> });</code>

<code>function show_panel(contents){</code><code> </code><code>
var panel = '&lt;div id="mappr_panel"&gt;\
' + contents + ' \
&lt;\/div&gt;';</code>

<code> $('#map').append(panel); // Puts the panel div inside the map div...</code><code>
}
</code>

<p>NOTE: jQuery&#8217;s remove() function was then used when we wanted to hide this panel.</p>
<h3>Real-time updating on map change or criteria change</h3>
<p>We needed the map to reload properties (incidentally we used an <a title="Google Maps tutorial - PHP/MySQL/XML" href="http://code.google.com/support/bin/answer.py?answer=65622&amp;topic=11364">AJAX approach</a>) and redraw following either a map movement (e.g. zoom, pan), or a change in search criteria.</p>

<p>The first was a simple case of :</p>

<code>GEvent.addListener(map, 'moveend', redraw_map);    // Call redraw_map() on drag / pan / zoom end</code>

<p>The second however, required the function to be triggered following a form change. Again, jQuery was used. By simply including <code>class="onchange"</code> on form elements that may change, we could harness jQuery&#8217;s selector syntax to actually apply the onchange event.</p>

<code>$(document).ready( function(){
$('.onchange').change(redraw_map);
}</code>

<p>The finished product can be seen by performing a map search at <a title="Chartex - Chartered Surveryors" href="http://www.chartex.co.uk">http://www.chartex.co.uk</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.kaweb.co.uk/blog/property-mapping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

