Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ContextErrorException: Notice: Undefined property: stdClass::$duration in
- /var/www/symfony/src/123/DepBundle/Controller/DefaultController.php line 217
- public function getDepartmentAction()
- {
- $doctrine = $this->getDoctrine();
- $em = $doctrine->getManager();
- $response = $request = Request::createFromGlobals();
- $locationid = $response->request->get( 'locationid' );
- $userselection = $response->request->get( 'userselection' );
- $niederlassungsrepo = $em->getRepository( 'MbsNiederlassungBundle:Niederlassung' );
- $niederlassung = $niederlassungsrepo->findOneById( $locationid );
- $bezeichnung = $niederlassung->getBezeichnung();
- $strasse = $niederlassung->getStrasse();
- $plz = $niederlassung->getPlz();
- $ort = $niederlassung->getOrt();
- $telefonbuero = $niederlassung->getTelefonbuero();
- $link = $this->generateUrl('_niederlassung', array('filiale' => $bezeichnung));
- $distance = $this->getDistance( $userselection, $plz ); <====== here i wanna call it
- $result = array("bezeichnung" => $bezeichnung,
- "strasse" => $strasse,
- "plz" => $plz,
- "ort" => $ort,
- "telefonbuero" => $telefonbuero,
- "link" => $link,
- "entfernung" => $distance['distance']);
- $encoder = [new JsonEncoder()];
- $normalizer = [new GetSetMethodNormalizer()];
- $serializer = new Serializer($normalizer, $encoder);
- $newData = $serializer->serialize($result, 'json');
- return new Response($newData);
- }
- private function getDistance($start,$end)
- {
- $from = urlencode($start);
- $to = urlencode($end);
- $data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=de-de&sensor=false");
- $data = json_decode($data);
- $time = 0;
- $distance = 0;
- foreach($data->rows[0]->elements as $road) {
- $time += $road->duration->value; <======= Line 217
- $distance += $road->distance->value;
- }
- $result['time'] = $time / 60;
- $result['distance'] = $distance / 1000;
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement