Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 18th, 2014  |  syntax: None  |  size: 2.15 KB  |  views: 64  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ContextErrorException: Notice: Undefined property: stdClass::$duration in    
  2. /var/www/symfony/src/123/DepBundle/Controller/DefaultController.php line 217
  3.        
  4. public function getDepartmentAction()
  5. {
  6.     $doctrine = $this->getDoctrine();
  7.     $em = $doctrine->getManager();
  8.  
  9.     $response = $request = Request::createFromGlobals();
  10.     $locationid = $response->request->get( 'locationid' );
  11.     $userselection = $response->request->get( 'userselection' );
  12.  
  13.     $niederlassungsrepo = $em->getRepository( 'MbsNiederlassungBundle:Niederlassung' );
  14.     $niederlassung = $niederlassungsrepo->findOneById( $locationid );
  15.  
  16.         $bezeichnung = $niederlassung->getBezeichnung();
  17.         $strasse = $niederlassung->getStrasse();
  18.         $plz = $niederlassung->getPlz();
  19.         $ort = $niederlassung->getOrt();
  20.         $telefonbuero = $niederlassung->getTelefonbuero();
  21.  
  22.         $link = $this->generateUrl('_niederlassung', array('filiale' => $bezeichnung));
  23.  
  24.     $distance = $this->getDistance( $userselection, $plz );   <====== here i wanna call it
  25.  
  26.     $result = array("bezeichnung" => $bezeichnung,
  27.                     "strasse" => $strasse,
  28.                     "plz" => $plz,
  29.                     "ort" => $ort,
  30.                     "telefonbuero" => $telefonbuero,
  31.                     "link" => $link,
  32.                     "entfernung" => $distance['distance']);
  33.  
  34.  
  35.     $encoder = [new JsonEncoder()];
  36.     $normalizer = [new GetSetMethodNormalizer()];
  37.     $serializer = new Serializer($normalizer, $encoder);
  38.  
  39.     $newData = $serializer->serialize($result, 'json');
  40.  
  41.     return new Response($newData);
  42. }
  43.        
  44. private function getDistance($start,$end)
  45. {
  46.     $from = urlencode($start);
  47.     $to = urlencode($end);
  48.  
  49.     $data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=de-de&sensor=false");
  50.     $data = json_decode($data);
  51.  
  52.     $time = 0;
  53.     $distance = 0;
  54.  
  55.     foreach($data->rows[0]->elements as $road) {
  56.         $time += $road->duration->value;            <=======   Line 217
  57.         $distance += $road->distance->value;
  58.     }
  59.  
  60.     $result['time'] = $time / 60;
  61.     $result['distance'] = $distance / 1000;
  62.  
  63.     return $result;
  64. }