public function testOriginWithCoordinate() { $origin = $this->getMock('Ivory\\GoogleMap\\Base\\Coordinate'); $this->distanceMatrixRequest->setOrigins(array($origin)); $origins = $this->distanceMatrixRequest->getOrigins(); $this->assertArrayHasKey(0, $origins); $this->assertSame($origin, $origins[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; }
/** * Processes the given request. * * Available prototypes: * - function process(array $origins, array $destinations) * - function process(Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest $request) * * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the request is not valid (prototypes). */ public function process() { $args = func_get_args(); if (isset($args[0]) && $args[0] instanceof DistanceMatrixRequest) { $distanceMatrixRequest = $args[0]; } elseif (isset($args[0]) && is_array($args[0]) && (isset($args[1]) && is_array($args[1]))) { $distanceMatrixRequest = new DistanceMatrixRequest(); $distanceMatrixRequest->setOrigins($args[0]); $distanceMatrixRequest->setDestinations($args[1]); } else { throw DistanceMatrixException::invalidDistanceMatrixRequestParameters(); } if (!$distanceMatrixRequest->isValid()) { throw DistanceMatrixException::invalidDistanceMatrixRequest(); } $response = $this->send($this->generateUrl($distanceMatrixRequest)); $distanceMatrixResponse = $this->buildDistanceMatrixResponse($this->parse($response->getBody())); return $distanceMatrixResponse; }