Locate nearby locations based on latitude and longitude (LAT,LNG) (continued)

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.