So this cannot be the problem, sorry.
Well -one error doesn't exclude another.
Here's working Arduino code for calculating distance between two points.
// calculate distance in rad between two points
float c_dist(float lat1,float lon1,float lat2,float lon2)
// the standard version of formulae yields unacceptable precision
// return acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1));
// alternative formulae (haversine)
const float two=2.0;
return two*asin(sqrt(square(sin((lat1-lat2)/two)) +
To get distance in meters you must multiply the returned value with earth's radius (#define EARTH_RADIUS 6371009.0).