public static String formatDistanceBetween(LatLng point1,LatLng point2){
  if (point1 == null || point2 == null) {
    return null;
  }
  NumberFormat numberFormat=NumberFormat.getNumberInstance();
  double distance=Math.round(SphericalUtil.computeDistanceBetween(point1,point2));
  if (distance >= 1000) {
    numberFormat.setMaximumFractionDigits(1);
    return numberFormat.format(distance / 1000) + DISTANCE_KM_POSTFIX;
  }
  return numberFormat.format(distance) + DISTANCE_M_POSTFIX;
}

public static String formatDistanceBetween ( LatLng point1 , LatLng point2 ) { if ( point1 == null || point2 == null ) { return null ; } NumberFormat numberFormat = NumberFormat . getNumberInstance ( ) ; double distance = Math . round ( SphericalUtil . computeDistanceBetween ( point1 , point2 ) ) ; if ( distance >= 1000 ) { numberFormat . setMaximumFractionDigits ( 1 ) ; return numberFormat . format ( distance / 1000 ) + DISTANCE_KM_POSTFIX ; } return numberFormat . format ( distance ) + DISTANCE_M_POSTFIX ; }
calculate distance between two latlng points and format it nicely for display . as this is a sample , it only statically supports metric units . a production app should check locale and support the correct units .
