latest reactions

spider
One way is to google for page which cont …
andy
you can find this tool here http://andy. …
Tjarko
Eej Walker, that's pretty cool, I will c …
Walker
Thanks for posting your thoughts. I modi …
Albert
Thanks !! …

Clicky Web Analytics
Use OpenDNS
ZERIGO DNS

Ultimate dns hosting based on pre-defined templates, DNS redirection and lot's more.

mxna feeds

CF101 Archive: September 2007 Object Oriented PizzaJob Opening for ColdFusion Developer at Arizona State UniversityMy New Experience Getting ColdFusion Builder 2 Console WorkingCF101 Archive: February 2007 Data Table GatewaysJob Opening for Sr. ColdFusion Developer in CA/ San Fernando ValleyColdFusion Supports HTTP Verbs PUT And DELETE (As Well As GET And POST)Best wishes for the new FuseboxCF101 Archive: January 2007 Data Access ObjectsOpen Source Conference For CFML DevelopersSkype Blocking Web Services with IIS, ColdFusion & RailoCF101 Archive: October 2006 Five Cool Things with ColdFusionGenerate a tag cloud from an RSS feed with ColdFusionColdFusion MeetUp: Cloudy with a Chance of Tests, with Mike HenkeReminder - Adobe CookbooksCF101 Archive: September 2006 A first look at FusionDebug

All files are strictly confidential: all information is classified.
© Copyright 2002 - 2012 mximize.com.
All right reserved.

Visit Carlos GallupaMXNA webfeed

Getting the closest locations based on Latitude / Longitude

I'm not going to explain what is being done here (SQL script) because I just don't understand. I searched a long time for this script and at the moment i'm not even sure where I got it... bottomline.. it works, and really really good.

Let's say you got the lat/lng from an http call to the Google API (small example below) and you want to get the nearest 10 other "stores" in the area around you.

<cfhttp url="http://maps.google.com/maps/geo?q=#yourpostcode-address#&gl=nl&output=csv&sensor=false&key=#yourGooglekey#" method="GET" />

<cfset aRet = listToArray(cfhttp.filecontent) />

<!--- Is it a good request and is the accuracy more then 5 (postcode level) --->
<cfif aRet[1] eq 200>
   -- call the stored procedure
   EXEC getstores @lat = #aRet[3]#
   ,@lng = #aRet[4]#
</cfif>

<!-- Save procedure in your database MSSQL 2000 and up. -->

CREATE PROCEDURE [dbo].[getstores] @lat float,  @lng float AS
DECLARE @radius float, @DegToRad float
SET @DegToRad = 57.29577951
SET @radius = 25000
SELECT TOP 10
    sto_city
    ,sto_name
    ,sto_lat
    ,sto_lng
    ,sto_street
    ,sto_postcode
    ,sto_tel
    ,sto_fax
    ,sto_email
    ,sto_url
    ,sto_supplier
    ,sto_cnt_code
    ,ROUND((ACOS((SIN(@lat/57.2958) * SIN(sto_lat/@DegToRad)) +(COS(@lat/@DegToRad) * COS(sto_lat/@DegToRad) *COS(sto_lng/@DegToRad - @lng/@DegToRad))))* 6387.7, 2) AS distance
FROM store
WHERE (sto_lat >= @lat - (@radius/111))
And (sto_lat <= @lat + (@radius/111))
AND (sto_lng >= @lng - (@radius/111))
AND (sto_lng <= @lng + (@radius/111))
AND (
     ISNUMERIC(sto_lat) = 1
    AND
    ISNUMERIC(sto_lat) = 1
)
ORDER BY distance


The distance column from the stored procedure is the total distance from the location you submitted to the Google API (postcode / address). Hope you can find a good use for this.. I did for several projects already :-)

4762 viewed | 3 opinion(s)  | del.icio.us | Digg it | Tjarko @ 21/12/09 23:43 cet


Reactions:

Bob wrote.... (mail)

Failed for me on the ROUND statement... are you missing a ) after the 6387.7?That seemed to fix the error for me, but I don't know if the results are accurate?

08 April 2010 16:13 cet  

swinefeaster wrote....

Btw the earth's circumference is 6371km, not 6387.7km

01 November 2010 8:11 cet  

Tjarko wrote.... (site)

Hi Swine, actually the earth radius is flexible. From Wikipedia "Distances from points on the surface to the center range from 6,353 km to 6,384 km"

The above sum is not from my person, but from the university of Delft in the Netherlands, I'm hoping that these guys know what they are doing because they also build navigational software.

If you have a better SQL statement, please share, that's what I did with this piece of code, unfortunately I'm not claiming that it's accurate to the point, but it's accurate enought for us to use in several online map based systems.

01 November 2010 9:08 cet  

Leave your comment

Your name


Your url/website/link/email....


Some room for your reaction is placed here..



The answer to the ultimate question is?? (42 ;-))




URL en mail addresses are translated for you... life sometimes is that simple!!