Solved

In ASP classic I need to search for the nearest plumbers within a 20 mile radius, given a zip code.

Posted on 2011-02-20
15
556 Views
Last Modified: 2012-05-11
This is a pretty common feature on many websites - like dating or "find a contractor" websites.

You'll enter in your zip code, then you enter in how many miles to "spread out" from this zip code, then the site displays for you all items within a, say, 5 mile radius of your zip code.

So I need to implement this functionality on my website but i have no idea where to start.

I have a database of every zip code in America.

And I have a database of all my plumbers around America

See image:

http://img17.imageshack.us/img17/3686/plumbers2.jpg

So when someone goes to my website and types in:

ZIP: 00501 Radius: 5

I need to show them all the plumbers I got within a 5 mile radius of their zip code.

Anyone got any ideas on how I would code that?

Since I have the longitude and latitude of all the zip codes, perhaps i'd have to do some sort of geometric heuristic?

I'm sure this is a classic computer science problem.

But I was only a computer science minor...

:)

little help?

Thanks!
0
Comment
Question by:bobbysdog
  • 7
  • 5
  • 3
15 Comments
 
LVL 7

Expert Comment

by:MrNed
ID: 34940403
What database are you using? For example PostgreSQL with the PostGIS geospatial extensions can do all that with the inbuilt function calls. Trying to do something your self would be tricky and most likely slow without a lot of effort at understanding things like how R-tree indexes work.
0
 

Author Comment

by:bobbysdog
ID: 34940506
wow really?

I'm just using MS Access and Classic ASP...
0
 
LVL 7

Expert Comment

by:MrNed
ID: 34940520
I guess it depends on how big your site needs to be (users, data size, etc). You could code it up yourself fairly quickly with simple geometry functions and if there is only one user that might be acceptable. However, I'm used to catering for 1000s of users so haven't touched Access/ASP in a loooong time :) Just found that MySQL has spatial extensions too if you prefer that to postgresql, but I have never used them.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:bobbysdog
ID: 34940633
ya i would hope the site would eventually have thousands of visits a day.

damn that is a good link you posted...
0
 
LVL 7

Expert Comment

by:MrNed
ID: 34940643
If you really want that much traffic, get off MS Access immediately :) It will NOT scale.
0
 
LVL 1

Expert Comment

by:axbernardi
ID: 34944824
Hi.
If you want a very rough procedure (but it might be enoght for your purpose) you can run a query that take into consideration the coordinate of the two Post Code.
Then you can compare them keeping in mind that 1 degree of latitude it's always 69.2 miles.
1 degree of longitude unfortunately can vary with the latitude, but for the whole USA the value is between 48 and 58 (it is basically cos(latidude)*69.2 ) miles.
A couple of comparisson and you are roughly there!
0
 

Author Comment

by:bobbysdog
ID: 34945772
>> "If you really want that much traffic, get off MS Access immediately :) It will NOT scale."

thanks - ya i know Access has its flaws. Unfortunately i'm not smart enough to use anything else. Hopefully, someone will buy my website for a million dollars and then they'll have to worry about optimizing it with a better database later :)

>> "If you want a very rough procedure (but it might be enoght for your purpose) you can run a query that take into consideration the coordinate of the two Post Code..."

hi

i think i follow your procedure. the thing is, there are 40,000 zip codes. So I think i'd need some sort of Spatial Database algo as described above - right?

0
 
LVL 1

Expert Comment

by:axbernardi
ID: 34945908
well, you said:

>> Since I have the longitude and latitude of all the zip codes, ...

so... there you go... that's your Spacial Database
0
 

Author Comment

by:bobbysdog
ID: 34946421
Right

so i have this grid of x y coords

but the point is, I have 40,000 of them.

so the point of this thread is to try to find an algo that will get the 10 nearest points to

33.405559, -86.95141

and to do this in a fraction of a second (so i dont keep the user waiting...) and to implement this in ASP classic and MS Access on a typical windows server

0
 
LVL 1

Accepted Solution

by:
axbernardi earned 500 total points
ID: 34947448
The initilal question was:
how to find the points at less than X miles from 33.405559, -86.95141.

Given the plumbers table done as
Name,ZIP,...

and the zips table done as
ZIP,lat,lon

the resulting query would be:

select plumbers.name,plumbers.ZIP from plumbers inner join zips on zips.ZIP=plumbers.ZIP
where abs(lat-33.405559)< X/55 and abs(lon- (-86.95141))<X/69.2

Open in new window


This query would actually not drow a circle but a square around the given point.

Generally speaking, the original point (the 33.405559, -86.95141) could be found with one first query at the beginning given the "search for" zip, with a simple
select lat,lon from zips where zip=TheGivenZip

Shouldn't take long to run this 2 query
0
 

Author Comment

by:bobbysdog
ID: 34957508
Oooohhh

I see what you're getting at.

Ya thats cool. My website does not need to be precise at all. In fact if it guesses with a wide radius thats probably better.

but in your code, it looks like its only getting one side of the point...no?

wouldnt i need something like:

WHERE abs(lat-33.405559) < X/55 AND abs(lat-33.405559) > X/55

AND

abs(lon- (-86.95141)) < X/69.2 AND abs(lon- (-86.95141)) > X/69.2
0
 
LVL 1

Expert Comment

by:axbernardi
ID: 34958893
No, you don't need that, that's the point of having an abs function!
so abs(33.41-33.45) = abs(-0.04) = 0.04
0
 

Author Comment

by:bobbysdog
ID: 34967519
hmm

doesnt the abs value of a number just delete the neg sign

so in this case:

abs(lat-33.405559) <  X/55

wouldnt that just give me all the data on top of 33.40

like everything above San Francisco or thereabouts?
0
 
LVL 1

Expert Comment

by:axbernardi
ID: 34968132
imagining X = 6 then X/55 = 0.11
33.5-33.4=0.1  --> abs= 0.1, included
33.3-33.4=-0.1 --> abs= 0.1 included
33.6-33.4=0.2  --> abs= 0.2, excluded
33.2-33.4=-0.2  --> abs= -0.2, excluded

so the formula will give you true for all values between 33.29 and 33.51
Ok??
0
 

Author Comment

by:bobbysdog
ID: 34994558
oh i think i got it

thanks so much for helping me!!!!!!!!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Displaying number of records depdning on table contents - classic asp 13 39
Math home work questions 5 96
Error viewing ASP page 12 165
Save ms data to server side. 19 46
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question