Beispiel #1
0
 /**
  * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponse
  * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException
  *
  * Description : calculate distance between to points
  */
 private function rangeCalculus()
 {
     $distanceMatrix = new DistanceMatrix(new CurlHttpAdapter());
     $address = $this->getCurrentUserAddress();
     $dest = $this->getContactAddress();
     $request = new DistanceMatrixRequest();
     $origin = array_map('current', $address);
     $request->setOrigins($origin);
     $request->setDestinations(array('20 rue Marceau, Paris, France'));
     $response = $distanceMatrix->process($request);
     return $response;
 }
 /**
  * Generates distance matrix URL API according to the request.
  *
  * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest $distanceMatrixRequest The distance matrix request.
  *
  * @return string The generated URL.
  */
 protected function generateUrl(DistanceMatrixRequest $distanceMatrixRequest)
 {
     $httpQuery = array('origins' => array(), 'destinations' => array());
     foreach ($distanceMatrixRequest->getOrigins() as $origin) {
         if (is_string($origin)) {
             $httpQuery['origins'][] = $origin;
         } else {
             $httpQuery['origins'][] = sprintf('%s,%s', $origin->getLatitude(), $origin->getLongitude());
         }
     }
     foreach ($distanceMatrixRequest->getDestinations() as $destination) {
         if (is_string($destination)) {
             $httpQuery['destinations'][] = $destination;
         } else {
             $httpQuery['destinations'][] = sprintf('%s,%s', $destination->getLatitude(), $destination->getLongitude());
         }
     }
     $httpQuery['origins'] = implode('|', $httpQuery['origins']);
     $httpQuery['destinations'] = implode('|', $httpQuery['destinations']);
     if ($distanceMatrixRequest->hasTravelMode()) {
         $httpQuery['mode'] = strtolower($distanceMatrixRequest->getTravelMode());
     }
     if ($distanceMatrixRequest->hasAvoidTolls() && $distanceMatrixRequest->getAvoidTolls()) {
         $httpQuery['avoidTolls'] = true;
     }
     if ($distanceMatrixRequest->hasAvoidHighways() && $distanceMatrixRequest->getAvoidHighways()) {
         $httpQuery['avoidHighways'] = true;
     }
     if ($distanceMatrixRequest->hasUnitSystem()) {
         $httpQuery['units'] = strtolower($distanceMatrixRequest->getUnitSystem());
     }
     if ($distanceMatrixRequest->hasRegion()) {
         $httpQuery['region'] = $distanceMatrixRequest->getRegion();
     }
     if ($distanceMatrixRequest->hasLanguage()) {
         $httpQuery['language'] = $distanceMatrixRequest->getLanguage();
     }
     $httpQuery['sensor'] = $distanceMatrixRequest->hasSensor() ? 'true' : 'false';
     $url = sprintf('%s/%s?%s', $this->getUrl(), $this->getFormat(), http_build_query($httpQuery));
     return $this->signUrl($url);
 }
 public function testProcessWithDistanceMatrixRequestAndAvoidHighways()
 {
     $request = new DistanceMatrixRequest();
     $request->addOrigin('Vancouver BC');
     $request->addDestination('San Francisco');
     $request->setAvoidHighways(true);
     $response = $this->service->process($request);
     $this->assertCount(1, $response->getOrigins());
     $this->assertCount(1, $response->getDestinations());
     $rows = $response->getRows();
     $this->assertCount(1, $rows);
     $elements = $rows[0]->getElements();
     $this->assertCount(1, $elements);
     $this->assertSame(DistanceMatrixElementStatus::OK, $elements[0]->getStatus());
 }
 public function testIsValidWithOriginAndDestination()
 {
     $this->distanceMatrixRequest->addDestination('foo');
     $this->distanceMatrixRequest->addOrigin('bar');
     $this->assertTrue($this->distanceMatrixRequest->isValid());
 }