Calculate distance between 2 GPS coordinates

前端 未结 29 3555
青春惊慌失措
青春惊慌失措 2020-11-21 23:34

How do I calculate distance between two GPS coordinates (using latitude and longitude)?

29条回答
  •  攒了一身酷
    2020-11-22 00:09

    A T-SQL function, that I use to select records by distance for a center

    Create Function  [dbo].[DistanceInMiles] 
     (  @fromLatitude float ,
        @fromLongitude float ,
        @toLatitude float, 
        @toLongitude float
      )
       returns float
    AS 
    BEGIN
    declare @distance float
    
    select @distance = cast((3963 * ACOS(round(COS(RADIANS(90-@fromLatitude))*COS(RADIANS(90-@toLatitude))+ 
    SIN(RADIANS(90-@fromLatitude))*SIN(RADIANS(90-@toLatitude))*COS(RADIANS(@fromLongitude-@toLongitude)),15)) 
    )as float) 
      return  round(@distance,1)
    END
    

提交回复
热议问题