Reputation: 2009
Sorry for not handled the GPS data before. may be a newbie question
So , I have created the table that store the gps data like this:
table name : request
id
lat decimal(10,8)
lng decimal(11,8)
Recently, I would like to get the data that is 10km within the given GPS point.
e.g. Given GPS lat: 22, lng: 114 , found all data within 10km
And I found there is a data type called "point". And a SQL query related
SELECT *
FROM request
WHERE MBRContains
(
LineString
(
Point (
@lng + 10 / ( 111.1 / COS(RADIANS(@lat))),
@lat + 10 / 111.1
),
Point (
@lng - 10 / ( 111.1 / COS(RADIANS(@lat))),
@lat - 10 / 111.1
)
),
POINTFROMTEXT('POINT(22 114)')
)
It return 0 result even there should be some result eg. I have some record that lat is 22.1 , 114.1 . How to fix it? Thanks.
Upvotes: 3
Views: 1374
Reputation: 4663
I'd reference this question, it was closed as a duplicate but the list of duplicates give you a pretty good overview of the problemset and solutions.
Radius of 40 kilometers using latitude and longitude
Upvotes: 1