If I have a table with
id, location, latitude, longitude
and I would have a location code: (13.779242,100.472915) for example.
! have 2 questions: what field type should I use for the lat and lon? Double? or maybe the spacial things? but isn't that more for calculating the distance?
Anyway, I want to find the location (or the one most accurate) Am I thinking to easily if I would just do these 2 queries:
Select * from location_table WHERE latitude > 13.779242 AND longitude > 100.472915." LIMIT 1"; // return as row 1
Select * from location_table WHERE latitude < 13.779242 AND longitude < 100.472915." LIMIT 1"; // return as row2
Then do a compare
$lat_dis_1 = $row1->latitude - 13.779242;
$lat_dis_2 = 13.779242 - $row2->latitude;
if ($lat_dis_1 > $lat_dis_2) {
// row2 was closer
} else {
//row1 closer
}
and same for longitude... Or am i just thinking too simpel here?