Google の Location.distance between & location.distanceto 関数の使用を停止します。それらは一貫して機能しません。
代わりに、直接式を使用して距離を計算します。
double distance_between(Location l1, Location l2)
{
//float results[] = new float[1];
/* Doesn't work. returns inconsistent results
Location.distanceBetween(
l1.getLatitude(),
l1.getLongitude(),
l2.getLatitude(),
l2.getLongitude(),
results);
*/
double lat1=l1.getLatitude();
double lon1=l1.getLongitude();
double lat2=l2.getLatitude();
double lon2=l2.getLongitude();
double R = 6371; // km
double dLat = (lat2-lat1)*Math.PI/180;
double dLon = (lon2-lon1)*Math.PI/180;
lat1 = lat1*Math.PI/180;
lat2 = lat2*Math.PI/180;
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double d = R * c * 1000;
log_write("dist betn "+
d + " " +
l1.getLatitude()+ " " +
l1.getLongitude() + " " +
l2.getLatitude() + " " +
l2.getLongitude()
);
return d;
}