This error is probably occurring because, according to the developer docs for the Distance Matrix API:
This product or feature is in Legacy status and cannot be enabled for new usage.