Get the nearest longitude and latitude from MSSQL database table?

前端 未结 5 1704
自闭症患者
自闭症患者 2020-12-08 17:50

Ok I have searched SO and Google but haven\'t really found a definitive answer so throwing it out there for the SO community.

Basically I have a table of longitudes

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 18:26

    Here how I used Mike's function above:

        SELECT TOP 1 [State], [City], [AddressID], sqrt(square(abs(la.Latitude-@lat)) + square(abs(la.Longitude-@lng))) as Distance
        FROM [LocationAddresses] la     
        ORDER BY Distance
    

提交回复
热议问题