<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: Zip code radius calculation algorithm</title>
	<atom:link href="http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Wed, 08 Feb 2012 19:15:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chris</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-532</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Tue, 04 Aug 2009 03:56:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-532</guid>
		<description>Here's the code I keep having an issue with. I get runtime error 3085 "Undefined function 'GetDistance' in expression...

Function GetDistance(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double

   GetDistance = Round(0.621371 * (6371 * ((2 * ASin(Sqr((Sin((Deg2Rad([lat1]) - Deg2Rad([lat2])) / 2) ^ 2 + Cos(Deg2Rad([lat1])) * Cos(Deg2Rad([lat2])) * (Sin((Deg2Rad([long1]) - Deg2Rad([long2])) / 2) ^ 2))))))), 4)

End Function


Private Sub cmdRadCalc_Click()

Dim db As Database
Dim rangeFactor As Double
Dim SQLCalc As String
rangeFactor = 0.014457

Set db = CurrentDb

SQLCalc = "SELECT Zip1 INTO tblRadResults FROM tblZipcodes WHERE tblZipcodes.[Lat]" &amp; _
"BETWEEN  txtRadLat-(txtRadDist*rangeFactor)  AND  txtRadLat+(txtRadDist*rangeFactor)" &amp; _
"AND  tblZipcodes.[long]  BETWEEN  txtRadLong-(txtRadDist*rangeFactor) AND txtRadLong+" &amp; _
"(txtRadDist*rangeFactor)AND GetDistance(txtRadLat, txtRadLong, tblZipcodes.[lat], tblZipcodes.[long])  &lt;= txtRadDist"


db.Execute SQLCalc
DoCmd.OpenTable "tblRadResults", acViewNormal, acReadOnly


End Sub</description>
		<content:encoded><![CDATA[<p>Here&#8217;s the code I keep having an issue with. I get runtime error 3085 &#8220;Undefined function &#8216;GetDistance&#8217; in expression&#8230;</p>
<p>Function GetDistance(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double</p>
<p>   GetDistance = Round(0.621371 * (6371 * ((2 * ASin(Sqr((Sin((Deg2Rad([lat1]) - Deg2Rad([lat2])) / 2) ^ 2 + Cos(Deg2Rad([lat1])) * Cos(Deg2Rad([lat2])) * (Sin((Deg2Rad([long1]) - Deg2Rad([long2])) / 2) ^ 2))))))), 4)</p>
<p>End Function</p>
<p>Private Sub cmdRadCalc_Click()</p>
<p>Dim db As Database<br />
Dim rangeFactor As Double<br />
Dim SQLCalc As String<br />
rangeFactor = 0.014457</p>
<p>Set db = CurrentDb</p>
<p>SQLCalc = &#8220;SELECT Zip1 INTO tblRadResults FROM tblZipcodes WHERE tblZipcodes.[Lat]&#8221; &amp; _<br />
&#8220;BETWEEN  txtRadLat-(txtRadDist*rangeFactor)  AND  txtRadLat+(txtRadDist*rangeFactor)&#8221; &amp; _<br />
&#8220;AND  tblZipcodes.[long]  BETWEEN  txtRadLong-(txtRadDist*rangeFactor) AND txtRadLong+&#8221; &amp; _<br />
&#8220;(txtRadDist*rangeFactor)AND GetDistance(txtRadLat, txtRadLong, tblZipcodes.[lat], tblZipcodes.[long])  &lt;= txtRadDist&#8221;</p>
<p>db.Execute SQLCalc<br />
DoCmd.OpenTable &#8220;tblRadResults&#8221;, acViewNormal, acReadOnly</p>
<p>End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-531</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Tue, 04 Aug 2009 03:37:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-531</guid>
		<description>Is it possible to do this in VBA? I've been trying this calc for some time now and I'm hitting a wall. I'm calculating the distance in VBA and wrote a FUNCTION that should calculate for each possible record. I am then using db.Execute to call a SQL statement that will show the records that fall within the radius. The SQL statement is dependant on the FUNCTION created in VBA, and that's where I think the problem is. I am very new to programming in both SQL and VBA, any help would be greatly appreciated.</description>
		<content:encoded><![CDATA[<p>Is it possible to do this in VBA? I&#8217;ve been trying this calc for some time now and I&#8217;m hitting a wall. I&#8217;m calculating the distance in VBA and wrote a FUNCTION that should calculate for each possible record. I am then using db.Execute to call a SQL statement that will show the records that fall within the radius. The SQL statement is dependant on the FUNCTION created in VBA, and that&#8217;s where I think the problem is. I am very new to programming in both SQL and VBA, any help would be greatly appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-503</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 26 May 2009 20:08:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-503</guid>
		<description>@Iryna, that's just part of *one* formula for calculating the distance between two waypoints. Like I said, there are many ways to calculate the distance, depending on how accurate you want to measure it. For most applications this formula will work just fine.</description>
		<content:encoded><![CDATA[<p>@Iryna, that&#8217;s just part of *one* formula for calculating the distance between two waypoints. Like I said, there are many ways to calculate the distance, depending on how accurate you want to measure it. For most applications this formula will work just fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Iryna</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-502</link>
		<dc:creator>Iryna</dc:creator>
		<pubDate>Tue, 26 May 2009 18:14:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-502</guid>
		<description>Can you please explain where does the number 3959 come from?

Thank you</description>
		<content:encoded><![CDATA[<p>Can you please explain where does the number 3959 come from?</p>
<p>Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-499</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Thu, 07 May 2009 23:20:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-499</guid>
		<description>I used the between clause instead of the whole &lt; =... makes more sense if someone looks at the sql later on at least to me</description>
		<content:encoded><![CDATA[<p>I used the between clause instead of the whole &lt; =&#8230; makes more sense if someone looks at the sql later on at least to me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John C</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-468</link>
		<dc:creator>John C</dc:creator>
		<pubDate>Mon, 09 Feb 2009 22:40:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-468</guid>
		<description>Got it,... thanks so much for taking the time to give a concrete example.
Best, John C</description>
		<content:encoded><![CDATA[<p>Got it,&#8230; thanks so much for taking the time to give a concrete example.<br />
Best, John C</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-467</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 09 Feb 2009 14:33:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-467</guid>
		<description>@ John C, my intent was to keep this article as general as possible so it would be applicable to any scripting/database language but perhaps a specific example will be helpful to others.

So - The SQL statement you would use to get the initial set of records within 10 miles of your target coordinates would be: 

&lt;code&gt;SELECT * FROM zip WHERE latitude &gt;= '40.681 - 0.20' AND latitude &lt;= '40.681 + 0.20' AND longitude &gt;= '-73.845 - 0.143' AND longitude &lt;= '-73.845 + 0.143';
&lt;/code&gt;

To eliminate the coordinates outside your radius (remember, the set returned by SQL is approximate and is a square, see the image in the post) you'll need to do some calculations to find exact distances between your target and EACH point. You probably won't want to do this in SQL since the calculations can be complicated (again, see above) - I choose to do this in PHP instead.</description>
		<content:encoded><![CDATA[<p>@ John C, my intent was to keep this article as general as possible so it would be applicable to any scripting/database language but perhaps a specific example will be helpful to others.</p>
<p>So - The SQL statement you would use to get the initial set of records within 10 miles of your target coordinates would be: </p>
<p><code>SELECT * FROM zip WHERE latitude >= '40.681 - 0.20' AND latitude < = '40.681 + 0.20' AND longitude >= &#8216;-73.845 - 0.143&#8242; AND longitude < = '-73.845 + 0.143';<br />
</code></p>
<p>To eliminate the coordinates outside your radius (remember, the set returned by SQL is approximate and is a square, see the image in the post) you&#8217;ll need to do some calculations to find exact distances between your target and EACH point. You probably won&#8217;t want to do this in SQL since the calculations can be complicated (again, see above) - I choose to do this in PHP instead.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John C</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-466</link>
		<dc:creator>John C</dc:creator>
		<pubDate>Mon, 09 Feb 2009 03:54:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-466</guid>
		<description>Thanks for the fast reply, sorry I have no idea what the ± symbol is? is that a plus-minus sign?. or I guess I can just use 0.143?. When doing this calculation?. Finally, is it on the SQL side?, because I notice you do a select statement like so.
SELECT * FROM zip WHERE latitude &gt;= ‘c’ AND latitude = ‘a’ AND longitude &lt;= ‘b’).

Or is it like, get the zip codes lat &amp; long where zip_code='somezip'  in a query, then calculate the c,d,a,b on this result set of the lat &amp; long returned. Then do another query using the calculation off of that?. Thanks so much for sharing and taking the time to reply.
Best, John C</description>
		<content:encoded><![CDATA[<p>Thanks for the fast reply, sorry I have no idea what the ± symbol is? is that a plus-minus sign?. or I guess I can just use 0.143?. When doing this calculation?. Finally, is it on the SQL side?, because I notice you do a select statement like so.<br />
SELECT * FROM zip WHERE latitude &gt;= ‘c’ AND latitude = ‘a’ AND longitude &lt;= ‘b’).</p>
<p>Or is it like, get the zip codes lat &amp; long where zip_code=&#8217;somezip&#8217;  in a query, then calculate the c,d,a,b on this result set of the lat &amp; long returned. Then do another query using the calculation off of that?. Thanks so much for sharing and taking the time to reply.<br />
Best, John C</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-465</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sun, 08 Feb 2009 13:18:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-465</guid>
		<description>@ John C, it's very simple: -73.845 ± 1/7 (or 0.143) and 40.681 ± 1/5.</description>
		<content:encoded><![CDATA[<p>@ John C, it&#8217;s very simple: -73.845 ± 1/7 (or 0.143) and 40.681 ± 1/5.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John C</title>
		<link>http://www.reviewapp.com/blog/2006/05/07/zip-code-radius-calculation-algorithm/comment-page-1/#comment-464</link>
		<dc:creator>John C</dc:creator>
		<pubDate>Sun, 08 Feb 2009 05:48:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.tripleblaze.com/blog/?p=75#comment-464</guid>
		<description>ok, say my longitude is -73.845 and the latitude is 40.681 and this is in some database, and I want to get the other zip codes in 10 mile radius. How do you calculate degrees by 1/7 ? to get points a and b?.  Whats the formula for something like that?. Any examples?
Thanks, John</description>
		<content:encoded><![CDATA[<p>ok, say my longitude is -73.845 and the latitude is 40.681 and this is in some database, and I want to get the other zip codes in 10 mile radius. How do you calculate degrees by 1/7 ? to get points a and b?.  Whats the formula for something like that?. Any examples?<br />
Thanks, John</p>
]]></content:encoded>
	</item>
</channel>
</rss>

