Select coordinates which fall within a radius of a central point?

后端 未结 3 916
遇见更好的自我
遇见更好的自我 2021-01-31 06:16

I have a database of coordinates in the schema:

ID:Latitude:Longitude:name:desc

I\'ve set up my google maps application to show the markers effectively on the sc

3条回答
  •  广开言路
    2021-01-31 06:50

    The SQL below should work:

    SELECT * FROM Table1 a 
    WHERE (
              acos(sin(a.Latitude * 0.0175) * sin(YOUR_LATITUDE_X * 0.0175) 
                   + cos(a.Latitude * 0.0175) * cos(YOUR_LATITUDE_X * 0.0175) *    
                     cos((YOUR_LONGITUDE_Y * 0.0175) - (a.Longitude * 0.0175))
                  ) * 3959 <= YOUR_RADIUS_INMILES
          )
    

    This is based on the spherical law of cosines, for more detailed information on the topic, check out this article - http://www.movable-type.co.uk/scripts/latlong.html

提交回复
热议问题