According to the current location of the coordinate point is also latitude and longitude, find the database near 5 km or 10 km near the implementation of all information, after looking for information, it is my sophomore school, is to find the string length, math forgot, did not think math is so useful, math ah really use too much.
Use what cosine, angle, radian all forget, but by looking for data, or realized, the error is relatively small, I implemented in the MSSQL database, specific as follows:
MSSQL functions:
ALTER FUNCTION [Getdistance] (
@GPSLng DECIMAL (12,6),
@GPSLat DECIMAL (12,6),
@Lng DECIMAL (12,6),
@Lat DECIMAL (12,6)
)
RETURNS DECIMAL (12,4)
As
BEGIN
DECLARE @result DECIMAL (12,4)
SELECT @result =6371.004*acos SIN (@GPSLat/180*pi ()) *sin (@Lat/180*pi ()) +cos (@GPSLat/180*pi ()) *cos (@Lat/180*pi ()) * COS ((@GPSLng-@Lng)/180*pi ())
Return @result
End
SQL query statement:
SELECT *,getdistance (longitude at some point, latitude of a certain point, longitude in database, latitude of database) as dis from table name dis<5
Find records within 5 km of a database
Note:
6371.004 Earth Radius
6371.004*acos (SIN (@GPSLat/180*pi ()) *sin (@Lat/180*pi ()) +cos (@GPSLat/180*pi ()) *cos (@Lat/180*pi ()) *cos (@ gpslng-@Lng)/180*pi ())--detailed explanation of the calculation formula of spherical arc length