public function calculateDistanceMatrix(array $origins, array $destinations) : DistanceMatrixResponse
    {
        $formattedOrigins      = $this->formatEntities($origins);
        $formattedDestinations = $this->formatEntities($destinations);

        $query = http_build_query([
            'origins'      => $formattedOrigins,
            'destinations' => $formattedDestinations,
            'key'          => $this->apiKey,
        ]);

        $url  = $this->generateBaseUrl() . '?' . $query;
        $data = $this->processRequest($url);

        if (!$this->checkResponseStatus($data)) {
            $data = $this->processRequest($url);
            if (!$this->checkResponseStatus($data)) {
                throw new ServiceProviderException('GoogleDistanceMatrix returned an unknown_error after retry');
            }
        }

        if (!array_key_exists('rows', $data)) {
            throw new ServiceProviderException('Missing key "rows" on data: ' . print_r($data, true));
        }

        return new DistanceMatrixResponse(
            $data['rows'],
            explode('|', $formattedOrigins),
            explode('|', $formattedDestinations),
            $data['origin_addresses'],
            $data['destination_addresses']
        );
    }