Zipcode 350 mile radius search.
Here is the output of the dump:
My question is: I want to LIMIT the query to the top 30 UNIQUE cities (not all Denver) - how can I do that?
Thanks,
Dave
Code:
<!--- Set the raduis of the search in miles --->
<cfset radiusMiles = 350>
<!--- Get one zipcode to create a raduis around --->
<cfquery name="GetZipInfo" datasource="#Application.DSN#">
SELECT *
FROM zipcodes
WHERE zip = 80202
</cfquery>
<!--- Get all zipcodes with the raduis --->
<cfquery datasource="#Application.DSN#" name="GetZipsWithinRaduis">
SELECT zip, latitude, longitude, stateAbv, city,
ROUND((ACOS((SIN(#GetZipInfo.latitude#/57.2958) * SIN(latitude/57.2958)) +
(COS(#GetZipInfo.latitude#/57.2958) * COS(latitude/57.2958) *
COS(longitude/57.2958 - #GetZipInfo.longitude#/57.2958))))
* 3963) AS distance
FROM zipcodes
WHERE (latitude >= #GetZipInfo.latitude# - (#radiusMiles#/111))
AND (latitude <= #GetZipInfo.latitude# + (#radiusMiles#/111))
AND (longitude >= #GetZipInfo.longitude# - (#radiusMiles#/111))
AND (longitude <= #GetZipInfo.longitude# + (#radiusMiles#/111))
ORDER BY distance
LIMIT 30
</cfquery>
<cfdump var="#GetZipsWithinRaduis#" label = "GetZipsWithinRaduis">
Here is the output of the dump:
My question is: I want to LIMIT the query to the top 30 UNIQUE cities (not all Denver) - how can I do that?
Thanks,
Dave