Find nearby businesses and sort by latitude and longitude

Source: Internet
Author: User
Tags cos pow sin

Recently in the project has a business need is through the mobile phone side of the latitude and longitude to query nearby businesses and according to various conditions, the project is MyBatis, the database is MySQL, in this record.

SELECTh.hotel_id hotelid,hotel_name Hotelname,ROUND(6378.138 * 2 * ASIN(SQRT(POW (SIN((#{lat}* PI()/  the -Latitude* PI()/  the) / 2),2) + COS(#{lat}* PI()/  the)* COS(Latitude* PI()/  the)*POW (SIN((#{lon}* PI()/  the -Longitude* PI()/  the) / 2),2))) *  +)  asDistance fromHotel HORDER  byDistance

where latitude and longitude are a property of the object in the database, LAT and long are the latitude and longitude of the mobile phone side, the calculated value is the meter.

Also consider paging and other factors, as well as the ability to use function calls, where only the distance algorithm is recorded.

Find nearby businesses and sort by latitude and longitude

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.