コード例 #1
0
 /**
  * Generates directions URL API according to the request.
  *
  * @param \Ivory\GoogleMap\Services\Directions\DirectionsRequest $directionsRequest The direction request.
  *
  * @return string The generated URL.
  */
 protected function generateUrl(DirectionsRequest $directionsRequest)
 {
     $httpQuery = array();
     if (is_string($directionsRequest->getOrigin())) {
         $httpQuery['origin'] = $directionsRequest->getOrigin();
     } else {
         $httpQuery['origin'] = sprintf('%s,%s', $directionsRequest->getOrigin()->getLatitude(), $directionsRequest->getOrigin()->getLongitude());
     }
     if (is_string($directionsRequest->getDestination())) {
         $httpQuery['destination'] = $directionsRequest->getDestination();
     } else {
         $httpQuery['destination'] = sprintf('%s,%s', $directionsRequest->getDestination()->getLatitude(), $directionsRequest->getDestination()->getLongitude());
     }
     if ($directionsRequest->hasWaypoints()) {
         $waypoints = array();
         if ($directionsRequest->hasOptimizeWaypoints() && $directionsRequest->getOptimizeWaypoints()) {
             $waypoints[] = 'optimize:true';
         }
         foreach ($directionsRequest->getWaypoints() as $waypoint) {
             $stopover = $waypoint->getStopover() ? 'via:' : '';
             if (is_string($waypoint->getLocation())) {
                 $waypoints[] = $stopover . $waypoint->getLocation();
             } else {
                 $waypoints[] = sprintf('%s%s,%s', $stopover, $waypoint->getLocation()->getLatitude(), $waypoint->getLocation()->getLongitude());
             }
         }
         $httpQuery['waypoints'] = implode('|', $waypoints);
     }
     if ($directionsRequest->hasTravelMode()) {
         $httpQuery['mode'] = strtolower($directionsRequest->getTravelMode());
     }
     if ($directionsRequest->hasProvideRouteAlternatives()) {
         $httpQuery['alternatives'] = $directionsRequest->getProvideRouteAlternatives() ? 'true' : 'false';
     }
     if ($directionsRequest->hasAvoidTolls() && $directionsRequest->getAvoidTolls()) {
         $httpQuery['avoid'] = 'tolls';
     } elseif ($directionsRequest->hasAvoidHighways() && $directionsRequest->getAvoidHighways()) {
         $httpQuery['avoid'] = 'highways';
     }
     if ($directionsRequest->hasUnitSystem()) {
         $httpQuery['units'] = strtolower($directionsRequest->getUnitSystem());
     }
     if ($directionsRequest->hasRegion()) {
         $httpQuery['region'] = $directionsRequest->getRegion();
     }
     if ($directionsRequest->hasLanguage()) {
         $httpQuery['language'] = $directionsRequest->getLanguage();
     }
     if ($directionsRequest->hasDepartureTime()) {
         $httpQuery['departure_time'] = $directionsRequest->getDepartureTime()->getTimestamp();
     }
     if ($directionsRequest->hasArrivalTime()) {
         $httpQuery['arrival_time'] = $directionsRequest->getArrivalTime()->getTimestamp();
     }
     $httpQuery['sensor'] = $directionsRequest->hasSensor() ? 'true' : 'false';
     $url = sprintf('%s/%s?%s', $this->getUrl(), $this->getFormat(), http_build_query($httpQuery));
     return $this->signUrl($url);
 }
コード例 #2
0
 public function testAvoidHighwaysWithNullValue()
 {
     $this->directionsRequest->setAvoidHighways(true);
     $this->directionsRequest->setAvoidHighways(null);
     $this->assertNull($this->directionsRequest->getAvoidHighways());
 }