Specify a latitude and longitude, given a range value, to find out the nearest 5 sets of data within this range around the latitude and longitude.
Longitude:116.312785
Latitude:39.929875
Range: 1 degrees (111 km)
Long is the data table longitude field
Lat for data table latitude field
Center for data table
The statement is tested under SQL Server, and other databases may need to be modified
Selecttop 5 *, ACOS (sin ((39.929875 * PI ())/P-P) * SIN ((lat * PI ())/) cos ((39.929875 * PI ())/+) * cos ((LAT * PI ( )) * COS ((116.312785 * PI ())/-(LONG * PI ())/) * 6380 as Aafromcenterwherelat > 39.929875-1and L At <39.929875 1AND long >116.312785-1and Long < 116.312785 1ORDER by AA------------------------------------- --------------------------------------------------If the data type is not float type, it needs to be converted to float type: cast (LAT as float)
SQL Server statement queries the specified location (latitude and longitude) in the range of information