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

后端 未结 3 906
遇见更好的自我
遇见更好的自我 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:53

    You probably need to do this in two steps. Select the points that lie within a 20 mile square with it's centre at X,Y. Assuming you calculate the top,left and bottom,right coordinates of the square first you can get all the points inside the square from the database with:

    select * from coordinates where longitude < right and longitude > left and 
    latitude < top and latitude > bottom;
    

    The second step is to see whether the set of points is inside the 10 mile radius circle. At this point I would be tempted to use Google maps to calculate the distance between the points and the centre of your square using the google.maps.geometry.spherical.computeDistanceBetween(from:LatLng, to:LatLng, radius?:number)function. Check the answer is less than 10 miles. This function uses the radius of the earth as a default.

提交回复
热议问题