Original source: http://blog.163.com/ezy_dk/blog/static/166651492201221445753585/
Reference Web: A preliminary study of nearby location search
The following is a summary of your own SQL code
Declare @EARTH_RADIUS float
Set @EARTH_RADIUS = 6371000.00-Earth's radius
declare @lat float
declare @lng float
declare @dlng float
declare @dlat float
declare @distance int --distance
set @distance = --300 m C9/>set @lat =xx.xxxxx -This is the central location
set @lng = xxx.xxxx -central location
set @dlng = 2 * ASIN (SIN (@distance /(2 * @EARTH_RADIUS))/cos (@lat))
Set @dlng = degrees (@dlng)
Set @dlat = 300/@EARTH_RADIUS
set @dla t = degrees (@dlat)
declare @lng1 float
declare @lng2 float
declare @lat1 float
declare @lat2 Float
Set @lat1 = @lat-@dlat- -Longitude
Set @lat2 = @lat + @dlat- -east longitude
Set @lng1 = @lng
Set @lng2 = @lng + @dlng --Northern latitude
Select @lat1, @lat2, @lng1, @lng2
select Lat,lng
from WHERE
(Lat > @lat1 and Lat < @lat2)- -longitude range
and
(LNG > @lng1 and LNG < @lng2)-- latitude range
Common sense:
1, Longitude (Latitude), longitude is positive, longitude is negative;
2, Latitude (longitude), latitude is positive, latitude is negative;
Figures: