SQL statement query latitude and longitude range

Source: Internet
Author: User

Specifies a latitude and longitude, given a range value (in kilometers), to isolate the data within this range around the latitude and longitude.
Longitude: 113.914619
Latitude: 22.50128
Range: 2km
Longitude as a data table longitude field
Latitude for the data table latitude field

SQL is tested under MySQL, other databases may need to be modified

The SQL statement is as follows: SELECT * from location where sqrt (

(

((113.914619-longitude) *pi () *12656*cos (((22.50128+latitude)/2) *pi ()/ +/+)

*

((113.914619-longitude) *pi () *12656*cos (((22.50128+latitude)/2) *pi ()/ +/+)

)

+

(

((22.50128-latitude) *pi () *12656/)

*

((22.50128-latitude) *pi () *12656/)

)

) <2&NBSP;&NBSP;

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.