You need to return your Google API key as a string see: https://developers.google.com/maps/documentation/directions/get-api-key see: https://developers.google.com/maps/documentation/directions/intro#Introduction
( ! ) Warning: Undefined array key 0 in /var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_streams.php on line 41
Call Stack
#TimeMemoryFunctionLocation
10.0015359536{main}( ).../chap_07_simple_rest_client_google_maps_streams.php:0
PHP 7 Cookbook
Start End  

( ! ) Warning: Attempt to read property "legs" on null in /var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php on line 23
Call Stack
#TimeMemoryFunctionLocation
10.0015359536{main}( ).../chap_07_simple_rest_client_google_maps_streams.php:0
20.3254371832include( '/var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php ).../chap_07_simple_rest_client_google_maps_streams.php:43

( ! ) Warning: foreach() argument must be of type array|object, null given in /var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php on line 23
Call Stack
#TimeMemoryFunctionLocation
10.0015359536{main}( ).../chap_07_simple_rest_client_google_maps_streams.php:0
20.3254371832include( '/var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php ).../chap_07_simple_rest_client_google_maps_streams.php:43

( ! ) Warning: Attempt to read property "bounds" on null in /var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php on line 63
Call Stack
#TimeMemoryFunctionLocation
10.0015359536{main}( ).../chap_07_simple_rest_client_google_maps_streams.php:0
20.3254371832include( '/var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php ).../chap_07_simple_rest_client_google_maps_streams.php:43

( ! ) Warning: Attempt to read property "copyrights" on null in /var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php on line 63
Call Stack
#TimeMemoryFunctionLocation
10.0015359536{main}( ).../chap_07_simple_rest_client_google_maps_streams.php:0
20.3254371832include( '/var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php ).../chap_07_simple_rest_client_google_maps_streams.php:43