Zip code radius query

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Zip code radius query

    I found this query in another post and since it appeared to be exactly what i
    needed, i copied it. thank you to the author.

    My problem is that it fails and gets an Undefined Function 'ACos' message.

    Can anyone help me troubleshoot this? it's been 2 hours and i'm getting jumpy.

    SELECT zipcode
    FROM zipcodes
    WHERE ROUND((Acos((SIN(#get_lat_long.latitude#/57.2958) *
    SIN(latitude/57.2958)) +
    (COS(#get_lat_long.latitude#/57.2958) * COS(latitude/57.2958) *
    COS(longitude/57.2958 - #get_lat_long.longitude#/57.2958)))) * 3963, 3) <= 20
    ORDER BY zipcode

    Thorlabs Guest

  2. Similar Questions and Discussions

    1. help with query code
      Debugging info: pdfselectlist (Datasource=prereg, Time=20ms, Records=3) in D:\htdocs\examples\mycfs\formprocess.cfm @ 14:33:32.032 SELECT *...
    2. Query of Queries in CF7 crashes code from CF5
      If anyone has a suggestion to this question, I would be most appreciative. In CF5, I was using a query to show current logged in users within our...
    3. zip code trig, radius calculations
      i have the code below to find the distance between two zips....but i want to find all the zips around another in a given distance (say 10 miles...
    4. Query return code question
      All... I'm having problems figuring out what pg_query() really returns when there is an error. The documentation says it returns "FALSE",...
    5. diff between query and sql code?
      in the example following here, it seems to be invoking the 'yourQuery' but the sql code is doing that same thing only based on an index lookup....
  3. #2

    Default Re: Zip code radius query

    I may be missing something, but your WHERE clause does not conform to expected
    syntax: WHERE fieldname op value. Where's your field name?

    Otherwise, since ColdFusion supports the arc cosine, use it to evaluate the
    function, as shown below.


    <CFSET foo = ROUND((Acos((SIN(#get_lat_long.latitude#/57.2958) *
    SIN(latitude/57.2958)) +
    (COS(#get_lat_long.latitude#/57.2958) * COS(latitude/57.2958) *
    COS(longitude/57.2958 - #get_lat_long.longitude#/57.2958)))) * 3963, 3)>

    jdeline Guest

  4. #3

    Default Re: Zip code radius query

    jdeline,

    WHERE clauses don't need to follow the syntax you gave. All that's absolutely
    necessary is that you have a condition that evaluates to a boolean. You don't
    even need to use a fieldname if you don't want. This will work:
    WHERE 1 = 1
    and meets expected SQL syntax.

    That said, Thorlabs' query is pulling in 2 fieldnames, latitude and longitude.

    Fieldname:
    ROUND((Acos((SIN(#get_lat_long.latitude#/57.2958) * SIN(latitude/57.2958)) +
    (COS(#get_lat_long.latitude#/57.2958) * COS(latitude/57.2958) *
    COS(longitude/57.2958 - #get_lat_long.longitude#/57.2958)))) * 3963, 3)

    Op:
    <=

    Value:
    20

    Thorlabs, what database are you on? You're calling a database function called
    Acos(), and it sounds like that doesn't exist in the database you're using.

    Kronin555 Guest

  5. #4

    Default Re: Zip code radius query

    If your up for changing your db around a some, here is the query I use that I
    found out on the net somewhere, works perfectly for me

    SELECT b.zipcode, b.state,
    (3956 * (2 * ASIN(SQRT(POWER(SIN(((a.latitude-b.latit?ude)*0.017453293)/2),2)
    + COS(a.latitude*0.017453293) *
    COS(b.latitude*0.017453293) *
    POWER(SIN(((a.longitude-b.long?itude)*0.017453293)/2),2))))) AS distance
    FROM zipcodes a, zipcodes b, zipcodes c
    WHERE
    a.zipcode = '02134' AND # <-- Your starting zipcode
    a.zipcode = c.zipcode AND (3956 * (2 *
    ASIN(SQRT(POWER(SIN(((a.latitude-b.latit?ude)*0.017453293)/2),2) +
    COS(a.latitude*0.017453293) * COS(b.latitude*0.017453293) *
    POWER(SIN(((a.longitude-b.long?itude)*0.017453293)/2),2)
    )))) <= 5 # <-- Your target radius
    GROUP BY distance

    rmorgan Guest

  6. #5

    Default Re: Zip code radius query

    That's for everyones help. Originally it was running on MS access. I trasnfered it to an SQL database and it now works fine.

    thanks to all for your help! great support as always.
    Thorlabs Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139