According to the current coordinate point is also the latitude and longitude, to find the database near 5 kilometers or 10 kilometers near the realization of all the information, after looking for information, the original is I sophomore learn, is to seek the chord length, mathematics forget, did not think mathematics is so useful, mathematics ah is really use too big.
Use of what cosine, angle, radian all forget, but by looking for information, or achieved, the error is relatively small, I implemented in the MSSQL database, specifically as follows:
MSSQL function:
ALTER FUNCTION [getdistance]( @GPSLng DECIMAL( A,6),@GPSLat DECIMAL( A,6),@Lng DECIMAL( A,6),@Lat DECIMAL( A,6))RETURNS DECIMAL( A,4) asBEGIN DECLARE @result DECIMAL( A,4) SELECT @result=6371.004*ACOS(SIN(@GPSLat/ the*PI())*SIN(@Lat/ the*PI())+COS(@GPSLat/ the*PI())*COS(@Lat/ the*PI())*COS((@GPSLng-@Lng)/ the*PI())) RETURN @resultEND
SQL query statement:
SELECT *, getdistance (longitude of a certain point, latitude of a certain point, database longitude, database latitude ) as from table name where dis < 5
Find records within 5 km of the database
Note:6371.004Earth radius6371.004*ACOS(SIN(@GPSLat/ the*PI())*SIN(@Lat/ the*PI())+COS(@GPSLat/ the*PI())*COS(@Lat/ the*PI())*COS((@GPSLng-@Lng)/ the*PI()) A detailed explanation of the calculation formula for calculating the spherical arc length
Reprint: http://blog.csdn.net/ecdyf1989/article/details/8077943/
GPS positioning, according to latitude and longitude to query the latitude and longitude of the location-sql method to achieve