问题描述:

I am searching for a solution in Android to check whether a GPS point will lie in given set of Start and End GPS location or not. For Example Mr A will start from point X and will reach point Z via Y. Now if Mr B given a location P then we want to check whether this point P is lying on the Mr A's route or not.

If it appears that GPS is not sufficient for it then you can suggest any other ways as well.

I am looking forward to hear back from you!!

I am assuming that "Given Set of Starting and Ending" means you have one defined root in your Database. My answer is based on same purpose. Have a look at to following method,

```
public static float getDistance (float lat1, float lng1, float lat2, float lng2 )
{
double earthRadius = 3958.75;
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;
int meterConversion = 1609;
return new Float(dist * meterConversion).floatValue();
}
```

Now you need to compare your Mr A's lat-lon values with the DB's one by one. If you the distance is few meters that means Mr A has visited that point. Using this logic you need to check all the GPS Point of Mr A with the root stored in your DB.