I am working on implimenting a search by distance or search by radius form on my GLinks installation.
I have a separate mySQL database of "ZipCodes" complete with longitude, latidude and state.
I found the free database and example query here: http://www.kevinroth.com
I need some help with the logic and implementation. Suggestions would be greatly appreciated.
My plan is to....
• Add columns for zip code, longitude and latitude to links table
• When a link is added to the directory, grab the zipcode from the add.html form,
• Lookup the zipcode in the separate "ZipCode" database and grab the longitude - latitude
• Put this info into the links table
• That should do it. I can then use a query to find...
• Links within XX miles of zip 12345
I do not know how to grab the longitude and latitude from zipcodes and put into links when a user adds a link.
Will I have to edit Add.pm (called via add.cgi)?
Is this best done with a plugin and hook?
Actually, thinking out loud... I could create a global that returns longitude/latitude when given a zipcode and distance(radius).
Can someone help me create a global from this code?
I will still need to get the longitude/latitude from "zipcodes" db into links table when a link is added,
then I can use the global on the search form to find links that match query.
# up to 50 miles away from zip 54915
SELECT o.ZipCode, o.State,
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((z.Latitude-o.Latitude)*0.017453293)/2),2) +
COS(z.Latitude*0.017453293) *
COS(o.Latitude*0.017453293) *
POWER(SIN(((z.Longitude-o.Longitude)*0.017453293)/2),2)
)))) AS Distance
FROM ZipCodes z,
ZipCodes o,
ZipCodes a
WHERE z.ZipCode = 54915 AND
z.ZipCode = a.ZipCode AND
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((z.Latitude-o.Latitude)*0.017453293)/2),2) +
COS(z.Latitude*0.017453293) *
COS(o.Latitude*0.017453293) *
POWER(SIN(((z.Longitude-o.Longitude)*0.017453293)/2),2)
)))) <= 50
ORDER BY Distance
Please help.
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com
I have a separate mySQL database of "ZipCodes" complete with longitude, latidude and state.
I found the free database and example query here: http://www.kevinroth.com
I need some help with the logic and implementation. Suggestions would be greatly appreciated.
My plan is to....
• Add columns for zip code, longitude and latitude to links table
• When a link is added to the directory, grab the zipcode from the add.html form,
• Lookup the zipcode in the separate "ZipCode" database and grab the longitude - latitude
• Put this info into the links table
• That should do it. I can then use a query to find...
• Links within XX miles of zip 12345
I do not know how to grab the longitude and latitude from zipcodes and put into links when a user adds a link.
Will I have to edit Add.pm (called via add.cgi)?
Is this best done with a plugin and hook?
Actually, thinking out loud... I could create a global that returns longitude/latitude when given a zipcode and distance(radius).
Can someone help me create a global from this code?
I will still need to get the longitude/latitude from "zipcodes" db into links table when a link is added,
then I can use the global on the search form to find links that match query.
Code:
# demo query for SQL searches for zipcodes # up to 50 miles away from zip 54915
SELECT o.ZipCode, o.State,
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((z.Latitude-o.Latitude)*0.017453293)/2),2) +
COS(z.Latitude*0.017453293) *
COS(o.Latitude*0.017453293) *
POWER(SIN(((z.Longitude-o.Longitude)*0.017453293)/2),2)
)))) AS Distance
FROM ZipCodes z,
ZipCodes o,
ZipCodes a
WHERE z.ZipCode = 54915 AND
z.ZipCode = a.ZipCode AND
(3956 * (2 * ASIN(SQRT(
POWER(SIN(((z.Latitude-o.Latitude)*0.017453293)/2),2) +
COS(z.Latitude*0.017453293) *
COS(o.Latitude*0.017453293) *
POWER(SIN(((z.Longitude-o.Longitude)*0.017453293)/2),2)
)))) <= 50
ORDER BY Distance
Please help.
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com