Closest location look up scripts

  • Axe
  • Genius
  • Genius
  • User avatar
  • Joined: Jan 07, 2004
  • Posts: 5744
  • Loc: Sub-level 28
  • Status: Offline

Post February 7th, 2004, 1:59 am

Okies... here we go.. it's 10 years since I left school, so I had to do a lil hunting around for calcultion formulas, but I think I got it right...

1 Mile basically works out to a 0.015 diference in latitude or longitude...

http://mathforum.org/dr.math/faq/formul ... angle.html

There's the URL I used for the calculation, and here's an image I was working to try and sort of demonstrate how I arrived at a 0.015:1 scale (Btw, all numbers ended up being rounded off to 2dp, except for latitude & longitude coordinates & differences).

Image

So, in this example, if you lived in zip code 94950, and you wanted all stores in a 50m radius, you'd first work out the difference...

50 * 0.015 = 0.75

So, if your zip code coords are 38.054433 x -122.777625

Your box would be...

Top left : 37.304433 x -122.027625
Top right : 38.804433 x -122.027625
Bottom left : 37.304433 x -123.527625
Bottom right : 38.804433 x -123.527625

So, you would search for all zip codes that had...

Latitude > 37.304433 AND
Latitude < 38.804433 AND
Longitude > -123.527625 AND
Longitude < -122.027625

Which would give all zip codes in that 100x100 mile square.

Then you look for all stores in those zip codes. Do each individual distance calculation on each store found. Anything found under 50m, add it to the array, anything over 50m, forget it and move onto the next one. Once all results are in, spew out the contents of the array.

Bear in mind, it's 4am now, and my head was already hurtin' before I started this, so I could be a lil bit off, hehe.

There's also a probably much more optimized way of doing this (actually getting the list of stores with fewer SQL queries), but this was the first logical method that struck me.

As I said, it was kinda left on the backburner for a while, but now I've actually gone n' done the calculations, I think I might go ahead and work on that part of my script a bit after this weekend's over (working all weekend, heh).

Have a play anyways, and let me know how you get along with it.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 7th, 2004, 1:59 am

  • jjarrett
  • Born
  • Born
  • No Avatar
  • Joined: Mar 04, 2004
  • Posts: 1
  • Status: Offline

Post March 4th, 2004, 8:57 am

Looking for this info myself is how I found this forum and thread via Google. In exchange for the script for distance between two zips, allow me to share two scripts I have found for getting a list of stores/dealers with in x miles:

http://internet-programming.org/sample.txt

and

http://forums.devshed.com/t40665/s.html

hth
John
john@logontexas.com

Post Information

  • Total Posts in this topic: 17 posts
  • Users browsing this forum: No registered users and 318 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.