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
( ! ) Notice: Resolving timed out after 4000 milliseconds in /var/www/html/php7cookbook/source/Application/Web/Client/Curl.php on line 45
Call Stack
#TimeMemoryFunctionLocation
10.0007360712{main}( ).../chap_07_simple_rest_client_google_maps_curl.php:0
20.0010363216Application\Web\Client\Curl::send( $request = class Application\Web\Request { protected $uri = 'https://maps.googleapis.com/maps/api/directions/json'; protected $method = 'GET'; protected $headers = ['HTTPS' => 'on', 'SSL_TLS_SNI' => 'luchiyuan.idv.tw', 'HTTP_ACCEPT' => '*/*', 'HTTP_USER_AGENT' => 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)', 'HTTP_COOKIE' => 'UNLIKELYSOURCE=fde75191ca2b2ba24ddee72bec9f0ce2; PHPSESSID=003536b6bb7f03a52fe8559e93e0e41b', 'HTTP_ACCEPT_ENCODING' => 'gzip, br, zstd, deflate', 'HTTP_HOST' => 'luchiyuan.idv.tw', 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'SERVER_SIGNATURE' => '<address>Apache/2.4.52 (Ubuntu) Server at luchiyuan.idv.tw Port 443</address>\n', 'SERVER_SOFTWARE' => 'Apache/2.4.52 (Ubuntu)', 'SERVER_NAME' => 'luchiyuan.idv.tw', 'SERVER_ADDR' => '192.168.1.10', 'SERVER_PORT' => '443', 'REMOTE_ADDR' => '216.73.217.62', 'DOCUMENT_ROOT' => '/var/www/html', 'REQUEST_SCHEME' => 'https', 'CONTEXT_PREFIX' => '', 'CONTEXT_DOCUMENT_ROOT' => '/var/www/html', 'SERVER_ADMIN' => 'webmaster@localhost', 'SCRIPT_FILENAME' => '/var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_curl.php', 'REMOTE_PORT' => '32917', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', 'REQUEST_URI' => '/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_curl.php', 'SCRIPT_NAME' => '/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_curl.php', 'PHP_SELF' => '/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_curl.php', 'REQUEST_TIME_FLOAT' => 1795274752.87445, 'REQUEST_TIME' => 1795274752]; protected $cookies = ['UNLIKELYSOURCE' => 'fde75191ca2b2ba24ddee72bec9f0ce2', 'PHPSESSID' => '003536b6bb7f03a52fe8559e93e0e41b']; protected $metaData = NULL; protected $transport = 'https'; protected $data = ['origin' => 'New York City', 'destination' => 'Redondo Beach', 'key' => 1] } ).../chap_07_simple_rest_client_google_maps_curl.php:40
38.4516365296trigger_error( $message = 'Resolving timed out after 4000 milliseconds' ).../Curl.php:45

( ! ) Warning: Attempt to read property "routes" on null in /var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_curl.php on line 41
Call Stack
#TimeMemoryFunctionLocation
10.0007360712{main}( ).../chap_07_simple_rest_client_google_maps_curl.php:0

( ! ) Warning: Trying to access array offset on null in /var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_curl.php on line 41
Call Stack
#TimeMemoryFunctionLocation
10.0007360712{main}( ).../chap_07_simple_rest_client_google_maps_curl.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.0007360712{main}( ).../chap_07_simple_rest_client_google_maps_curl.php:0
28.4525369160include( '/var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php ).../chap_07_simple_rest_client_google_maps_curl.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.0007360712{main}( ).../chap_07_simple_rest_client_google_maps_curl.php:0
28.4525369160include( '/var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php ).../chap_07_simple_rest_client_google_maps_curl.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.0007360712{main}( ).../chap_07_simple_rest_client_google_maps_curl.php:0
28.4525369160include( '/var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php ).../chap_07_simple_rest_client_google_maps_curl.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.0007360712{main}( ).../chap_07_simple_rest_client_google_maps_curl.php:0
28.4525369160include( '/var/www/html/php7cookbook/source/chapter07/chap_07_simple_rest_client_google_maps_template.php ).../chap_07_simple_rest_client_google_maps_curl.php:43