So I have a project with GPS module and I want to search route with Google Maps. I have done implementing GPS with Google Maps, but now I come into a problem. I don't know if user still on track.
I get this array of steps from API Response:
"steps" :
[
{
"distance" :
{
"text" : "50 m",
"value" : 50
},
"duration" :
{
"text" : "1 min",
"value" : 39
},
"end_location" :
{
"lat" : -7.282490199999999,
"lng" : 112.7951477
},
"html_instructions" : "Head \u003cb\u003esoutheast\u003c/b\u003e",
"polyline" :
{
"points" : "phmk@ufmoTr@o@JO"
},
"start_location" :
{
"lat" : -7.2821734,
"lng" : 112.7948261
},
"travel_mode" : "WALKING"
},
...
Above is the example of 1 steps. Currently, I take the latitude and longitude and using Harvine Formula to find the distance from the GPS to the end_location. I use this function to count distance:
// Count distance in meters
double getDistanceInM(double lat1, double lon1, double lat2, double lon2) {
double R = 6335439; // Radius of the earth in m
double dLat = deg2rad(lat2 - lat1); // convert degrees to radians
double dLon = deg2rad(lon2 - lon1);
double a = sin(dLat/2) * sin(dLat/2) +
cos(deg2rad(lat1)) * cos(deg2rad(lat2)) *
sin(dLon/2) * sin(dLon/2);
double c = 2 * atan2(sqrt(a), sqrt(1-a));
double d = R * c; // Distance in m
return d;
}
After that I wait till the distance is below 5m before I instruct a new route to the user.
But how to know if user walking in the intended route. What if the user miss a turn. How can I know this?
I thought about counting distance between this step end_location and next step end_location. I thought that user should be closer to this step end_location then next_step end location, but I don't think this is the right way to do it