find the nearest location in ms-sql

前端 未结 3 1024
故里飘歌
故里飘歌 2021-02-08 18:10

I send these paramaters my script : Latitude : 41.0186 Longitude : 28.964701 (it is sample). i want to find nearest location\'s name. how to do this? (query\'s where code\'s mus

3条回答
  •  感情败类
    2021-02-08 18:43

    declare @latitude float, @longitude float
    select @latitude = 41.0186, @longitude = 28.964701
    
     SELECT [Name]   --, other columns
          ,Distance
          from
          (
          select 
          [Name]       --, other columns 
           ,( 3959 * acos( cos( radians(@latitude) ) * cos( radians( [Lattitude] ) ) * cos( radians( [Longitude] )
           - radians(@longitude) ) + sin( radians(@latitude) ) * sin( radians( [Lattitude] ) ) ) ) 
           AS Distance  FROM [dbo].[Location]
       ) as x   
        where Distance < 5   
      order by distance
    

提交回复
热议问题