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