Re: geographical proximity matching

by "John Aitchison" <jaitchis(at)hwy.com.au>

 Date:  Mon, 5 Nov 2001 19:07:31 +1100
 To:  Hank Marquardt <hmarq(at)yerpso.net>
 Cc:  hwg-techniques(at)hwg.org
 References:  baylogic
  todo: View Thread, Original
On 4 Nov 2001, at 7:09, Hank Marquardt wrote:

> You need a couple things --
> 
> First you have to go find the lat/long data for all the zip codes you
> plan on covering -- it's available free from the governement someplace
> though I forget where -- it's been a while since I did this, but I'd
> try the census bureau and the USGS first.
> 
> Then you'll need to code your database routine to join in this table
> during a search so you have the lat/long stuff for each record, and
> then do a separate lookup on the zip asked for by the client.
> 
> Then you'll need this function (in php) to compute and return the
> distance between two points).  
> 
> function
> LLDist($FirstLatitude,$SecondLatitude,$FirstLongitude,$SecondLongitude
> ) {
>  $milesDiff = 3958.75 * acos(  sin($FirstLatitude/57.2958) *
>  sin($SecondLatitude/57.2958) + cos($FirstLatitude/57.2958) *
>  cos($SecondLatitude/57.2958) * cos($SecondLongitude/57.2958 -
>  $FirstLongitude/57.2958)); return $milesDiff; }	
> 
> 
> The trick would be if you have to cover a 'big' geography with lots
> and lots of stores how to preliminarily wittle down the dataset so as
> not to do a full table scan on all records before computing the
> distance differential --

As I recall it, you can use kd trees for this . Plentty of stuff on 
computational geometry on the web, have a look at 
http://www.rolemaker.dk/nonRoleMaker/uni/algogem/kdtree.htm
for an idea of how it might apply. Also, Voronoi tesselations etc .
As long as the number of stores (locations)  is not large, there is 
little justification for doing any of this stuff - but it might be fun <g>





 I suppose it's possible to to actually encode
> the math into an SQL statement if your db supports all the trig stuff,
> I wasn't that adventurous though.
> 
> For the curious, this is in use at www.eautodealersearch.com -- it's
> where I did the code;)
> 
> Have a happy.
> 
> Hank
> On Sun, Nov 04, 2001 at 05:33:30AM -0500, Robert Clendaniel wrote: >
> We have a potential client with a chain of stores.  They want an >
> applet that will take a zip code, consult their list of locations > by
> zip code, and return the store location(s) information (if > there is
> an exact match) or the four or five closest locations > (if there
> isn't). > > I've seen this sort of thing on various sites but don't
> know how > I'd do it.  Has anyone here done this sort of thing? > >
> The central problem is obviously the zip code proximity > algorithm. 
> If there was a pre-programmed solution we'd > definitely consider
> buying it. > > TIA to anyone who can advise. > > Robert L. Clendaniel
> > BayLogic Internet Marketing Inc. > robert(at)baylogic.com >
> http://www.baylogic.com/
> 
> -- 
> Hank Marquardt <hank(at)yerpso.net>
> http://web.yerpso.net
> 
> Web & Database Development in PHP, MySQL/PostgreSQL
> Small Office Networking Solutions - Debian GNU/Linux & FreeBSD
> PHP Instructor - International Webmasters Assn./HTML Writers Guild ***
> Beginning PHP -- Starts November 5, 2001 *** See
> /services/classes
> 
> 

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.