Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting from distance for geography coordinates
Message
From
22/11/2011 12:41:31
 
 
To
22/11/2011 11:46:18
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01529492
Message ID:
01529559
Views:
21
>>Use a subselect?
>>
>> Something like - untested
>>
>>select 	Result.Numero,
>>	Result.Latitude, 
>>	Result.Longitude,
>>	Result.Distance 
>>  from
>>
>>	( SELECT Client.Numero,
>>		 Client.Latitude,
>>		 Client.Longitude, 
>>		3958.75586574*ACOS(
>>		 CASE WHEN SIN(@Latitude3/57.2957795130823)*SIN(Client.Latitude/57.2957795130823)+
>>		 COS(@Latitude4/57.2957795130823)*COS(Client.Latitude/57.2957795130823)*
>>		 COS(Client.Longitude/57.2957795130823-@Longitude3/57.2957795130823)<-1
>>		 THEN -1
>>		WHEN SIN(@Latitude5/57.2957795130823)*SIN(Client.Latitude/57.2957795130823)+
>>		COS(@Latitude6/57.2957795130823)*COS(Client.Latitude/57.2957795130823)*
>>		COS(Client.Longitude/57.2957795130823-@Longitude4/57.2957795130823)>1
>>		THEN 1
>>		ELSE SIN(@Latitude7/57.2957795130823)*SIN(Client.Latitude/57.2957795130823)+
>>		COS(@Latitude8/57.2957795130823)*COS(Client.Latitude/57.2957795130823)*
>>		COS(Client.Longitude/57.2957795130823-@Longitude5/57.2957795130823)
>> 		END) as Distance 
>>	) Result
>>
>>   where (Distance <= 250)
>>
>>
>
>This works, thanks
>
>I added FROM Client after as Distance.


By the way

You are using a constant 3958.75586574. I believe this is the radius of the earth in miles. If you want km, I'd use 6371

Source - http://www.movable-type.co.uk/scripts/latlong-db.html
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform