this is a similar question here but only 1 difference. the mysql is as follows.
ID | lat | lng | timestamp
1 | 23.21465 | 84.37856 | 2016-01-01 00:00:00
2 | 23.21465 | 84.37856 | 2016-01-01 00:03:00
3 | 23.21584 | 84.37877 | 2016-01-01 00:06:00
4 | 23.21584 | 84.37877 | 2016-01-01 00:09:00
5 | 23.21465 | 84.37856 | 2016-01-01 00:12:00
6 | 23.21465 | 84.37856 | 2016-01-01 00:15:00
7 | 23.21465 | 84.37856 | 2016-01-01 00:18:00
8 | 23.21465 | 84.37856 | 2016-01-01 00:21:00
although there is a change in lat(latitude) and lng(longitude) in rows 3 and 5 here in this case it should select only row with id 5 only.
The algorithm would be as follows:
(a) arrange the table in acsending order of timestamp
(b) check last row i.e. 8th row. compare latitude , longitude values with row 7. if they are same precede to compare with row 6 and so on until there is a change in latitude and longitude values . here in this case it would be row 4. then print row 5
(c) if the 8th row and 7the row latitude,longitude values are different then do nothing.
EDIT: In a nutshell, I'm simply after the earliest instance of the current values, or the last time the values changed.