public function GenerateMap($first = '', $second = '')
{
if ($first == '') {
$first = 'mannheim';
}
$address1 = $first;
$prepAddr1 = str_replace(' ', '+', $address1);
$geocode1 = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=' . $prepAddr1 . '&sensor=false');
$output1 = json_decode($geocode1);
$latitude1 = $output1->results[0]->geometry->location->lat;
$longitude1 = $output1->results[0]->geometry->location->lng;
if ($second == '') {
$second = 'berlin';
}
$address2 = $second;
$prepAddr2 = str_replace(' ', '+', $address2);
$geocode2 = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=' . $prepAddr2 . '&sensor=false');
$output2 = json_decode($geocode2);
$latitude2 = $output2->results[0]->geometry->location->lat;
$longitude2 = $output2->results[0]->geometry->location->lng;
$coord = new LatLng(['lat' => $latitude1, 'lng' => $longitude1]);
$map = new Map(['center' => $coord, 'zoom' => 14]);
// lets use the directions renderer
$home = new LatLng(['lat' => $latitude1, 'lng' => $longitude1]);
$school = new LatLng(['lat' => $latitude2, 'lng' => $longitude2]);
$directionsRequest = new DirectionsRequest(['origin' => $home, 'destination' => $school, 'travelMode' => TravelMode::DRIVING]);
// Lets configure the polyline that renders the direction
$polylineOptions = new PolylineOptions(['strokeColor' => '#FFAA00', 'draggable' => true]);
// Now the renderer
$directionsRenderer = new DirectionsRenderer(['map' => $map->getName(), 'polylineOptions' => $polylineOptions]);
// Finally the directions service
$directionsService = new DirectionsService(['directionsRenderer' => $directionsRenderer, 'directionsRequest' => $directionsRequest]);
// Thats it, append the resulting script to the map
$map->appendScript($directionsService->getJs());
return $map;
}