SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    SQL ZipCode Radius

    Does anyone have a ZipCode Radius based on Lat and Long algorithm they can share?

    The following i have is pretty complex I want to have to simplified and it shows all zipcodes in the radius but the one entered lol which is kind of silly.

    Code:
    SELECT 3956 * 2 * ATAN2(SQRT(POW(SIN((RADIANS(26.371027) - RADIANS(z.lat)) / 2), 2) + COS(RADIANS(z.lat)) * COS(RADIANS(26.371027)) * POW(SIN((RADIANS(-80.088766) - RADIANS(z.lon)) / 2), 2)), SQRT(1 - POW(SIN((RADIANS(26.371027) - RADIANS(z.lat)) / 2), 2) + COS(RADIANS(z.lat)) * COS(RADIANS(26.371027)) * POW(SIN((RADIANS(-80.088766) - RADIANS(z.lon)) / 2), 2))) AS "miles", z.* FROM dir_gen z WHERE zip_code <> '33431' AND lat BETWEEN ROUND(26.371027 - (25 / 69.172), 4) AND ROUND(26.371027 + (25 / 69.172), 4) AND lon BETWEEN ROUND(-80.088766 - ABS(25 / COS(26.371027) * 69.172)) AND ROUND(-80.088766 + ABS(25 / COS(26.371027) * 69.172)) AND 3956 * 2 * ATAN2(SQRT(POW(SIN((RADIANS(26.371027) - RADIANS(z.lat)) / 2), 2) + COS(RADIANS(z.lat)) * COS(RADIANS(26.371027)) * POW(SIN((RADIANS(-80.088766) - RADIANS(z.lon)) / 2), 2)), SQRT(1 - POW(SIN((RADIANS(26.371027) - RADIANS(z.lat)) / 2), 2) + COS(RADIANS(z.lat)) * COS(RADIANS(26.371027)) * POW(SIN((RADIANS(-80.088766) - RADIANS(z.lon)) / 2), 2))) <= 5 AND 3956 * 2 * ATAN2(SQRT(POW(SIN((RADIANS(26.371027) - RADIANS(z.lat)) / 2), 2) + COS(RADIANS(z.lat)) * COS(RADIANS(26.371027)) * POW(SIN((RADIANS(-80.088766) - RADIANS(z.lon)) / 2), 2)), SQRT(1 - POW(SIN((RADIANS(26.371027) - RADIANS(z.lat)) / 2), 2) + COS(RADIANS(z.lat)) * COS(RADIANS(26.371027)) * POW(SIN((RADIANS(-80.088766) - RADIANS(z.lon)) / 2), 2))) >= 0 ORDER BY 1 ASC
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,651
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Which flavor of database server? Some have native GIS capabilities that can handle these sorts of tasks in a more succint manner.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •