<?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>Kevin Bradwick &#187; radius</title>
	<atom:link href="http://www.kevinbradwick.co.uk/tag/radius/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kevinbradwick.co.uk</link>
	<description>Web development and design blog</description>
	<lastBuildDate>Fri, 09 Jul 2010 08:11:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Calculating the radius of a coordinate using PHP</title>
		<link>http://www.kevinbradwick.co.uk/2010/01/calculating-the-radius-of-a-coordinate-using-php/</link>
		<comments>http://www.kevinbradwick.co.uk/2010/01/calculating-the-radius-of-a-coordinate-using-php/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 18:23:11 +0000</pubDate>
		<dc:creator>kevin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[radius]]></category>

		<guid isPermaLink="false">http://www.kevinbradwick.co.uk/?p=59</guid>
		<description><![CDATA[Sometimes you&#8217;ll want to get the radius of a location. For this I have written a function that I&#8217;ll share with you. /* Copyright 2009 Kevin Bradwick (http://www.kevinbradwick.co.uk) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you&#8217;ll want to get the radius of a location. For this I have written a function that I&#8217;ll share with you.</p>
<pre name="code" class="php">/*

Copyright 2009  Kevin Bradwick (http://www.kevinbradwick.co.uk) 

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. 

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
*/

function geoRadius($lat, $lng, $rad, $kilometeres = FALSE, $out = 'OBJ')
	{
		$radius = ($kilometers) ? ($rad * 0.621371192) : $rad;

		(float)$dpmLAT = 1 / 69.1703234283616; 

		// Latitude calculation
		(float)$usrRLAT = $dpmLAT * $radius;
		(float)$latMIN = $lat - $usrRLAT;
		(float)$latMAX = $lat + $usrRLAT;

		// Longitude calculation
		(float)$mpdLON = 69.1703234283616 * cos($lat * (pi/180));
		(float)$dpmLON = 1 / $mpdLON; // degrees per mile longintude
		$usrRLON = $dpmLON * $radius;
		$lonMIN = $lng - $usrRLON;
		$lonMAX = $lng + $usrRLON;

		$output = array("lonMIN" =&gt; $lonMIN, "lonMAX" =&gt; $lonMAX, "latMIN" =&gt; $latMIN, "latMAX" =&gt; $latMAX);
		return ($out == 'OBJ') ? (object)$output : $output;
	}
</pre>
<p>Okay, so how do you use it? Well, the first two paramaters are the Latitude and Longitude of your origin. The third is the radius ammount. If you want to calculate it based on kilometers (default is in miles), enter a boolean value of TRUE for the fourth parameter. The last paramter specifices the output method, by default it will return an object, enter anything other that OBJ here will return an associative array.</p>
<p>So, once we&#8217;ve done that what do we have? You will then have 4 variables to use, each of them minimum and maximum values of Latitude and Longitude. This is how you could use the output of this function to query a database that contains geo data.</p>
<pre name="code" class="php">$radius = geoRadius(53.741690, -2.397750, 48.28032);
$sql = "SELECT * FROM `mytable` WHERE `latitude` BETWEEN {$radius-&gt;latMIN} AND {$radius-&gt;latMAX} AND `longitude` BETWEEN {$radius-&gt;lonMIN} AND {$radius-&gt;lonMAX}";
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinbradwick.co.uk/2010/01/calculating-the-radius-of-a-coordinate-using-php/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
