/** * @param Route $route * @return Uri */ private function createUri(Route $route) { $cnt = 1; $max = self::MAX_WAYPOINTS_LIMIT + 1; $start = null; $waypoints = []; $end = null; $start = $route->getCurrentCoordinate(); while (($coordinate = $route->getNextCoordinate()) && $cnt <= $max) { $waypoints[] = $coordinate; $cnt++; } $end = array_pop($waypoints); $origLat = $start->getLatitude(); $origLng = $start->getLongitude(); $destLat = $end->getLatitude(); $destLng = $end->getLongitude(); $uriString = $this->serviceEndpoint . "origin={$origLat},{$origLng}" . "&destination={$destLat},{$destLng}"; $uriString .= $this->addWaypoints($waypoints); $uriString .= "&key={$this->apiKey}"; return new Uri($uriString); }