/** * @expectedException \Ivory\GoogleMap\Exception\DirectionsException * @expectedExceptionMessage The directions request avoid hightways flag must be a boolean value. */ public function testAvoidHighwaysWithInvalidValue() { $this->directionsRequest->setAvoidHighways('foo'); }
public function ajaxAction(Request $request) { if ($request->isXmlHttpRequest()) { // $session = $request->getSession(); // $latitude = json_decode( $session->get('lat') ); // $longitude = json_decode( $session->get('lng') ); $latitude = $request->request->get('lat'); $longitude = $request->request->get('lng'); $coordpolaire = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng=" . $latitude . "," . $longitude . "&key=AIzaSyDePZt3uyPPCISJtyM5nvkmL_s5YxjcqBo"); $json = json_decode($coordpolaire); // echo '<pre>'; // var_dump($json->{'results'}[0]->{'formatted_address'}); // echo '</pre>'; $address = $json->{'results'}[0]->{'formatted_address'}; // $latitude = json_decode($request->request->get('lat')); // $longitude = json_decode($request->request->get('lng')); $em = $this->getDoctrine()->getManager(); $fiches = $em->getRepository('ProjetAppBundle:Fiche')->findBy(array('status' => '1', 'user' => $this->getUser())); $res = array(); $lol = ""; foreach ($fiches as $fiche) { $directionRequest = new DirectionsRequest(); $directionRequest->setOrigin($address, false); // $directionRequest->setOrigin("46 rue jules ferry 14120 mondeville", true); $directionRequest->setDestination($fiche->addressString(), true); $directionRequest->setAvoidHighways(true); $directionRequest->setAvoidTolls(true); $directionRequest->setTravelMode(TravelMode::DRIVING); $directionRequest->setUnitSystem(UnitSystem::METRIC); $directions = new Directions(new CurlHttpAdapter()); $responseDirection = $directions->route($directionRequest); $routes = $responseDirection->getRoutes(); foreach ($routes as $route) { $res = $route; } } // $encoders = new JsonEncoder(); // $normalizers = array(new GetSetMethodNormalizer()); // $serializer = new Serializer($normalizers, $encoders); // $json = $serializer->serialize($res, 'json'); $response = new Response($json); $response->headers->set('Content-Type', 'application/json'); return $response; // return new JsonResponse($lol); } }
public function testRouteWithDirectionsRequestAndAvoidHighways() { $request = new DirectionsRequest(); $request->setOrigin('Lille'); $request->setDestination('Paris'); $request->setAvoidHighways(true); $response = $this->directions->route($request); $this->assertSame(DirectionsStatus::OK, $response->getStatus()); $this->assertNotEmpty($response->getRoutes()); }