Level 1
I got it just need to js_decode the result.
dd(json_decode($result->getBody()));
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey friends,
I have an issue with the Google Maps API. I want to connect the maps API with GuzzleHttp. I do have a connection with status 200, but I don't have any useable content in my body. I run Laravel 6 on win 10 and xampp.
Here is my small Service I wrote so far:
<?php
namespace App\Services;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
class GoogleMapsService
{
private $api_key = "xxx"; // replace with your google maps api key
public function __construct()
{
}
public function testRoute()
{
$client = new Client();
$result = $client->request('GET', 'https://maps.googleapis.com/maps/api/directions/json',
['query' => [
'origin' => 'Disneyland',
'destination' => 'Universal+Studios+Hollywood',
'key' => $this->api_key
]
]);
dd($result);
}
}
Of course you have to replace the api key :)
If you type the url manually in the browser you get useable content, but not with guzzle. What do I do wrong?
I got it just need to js_decode the result.
dd(json_decode($result->getBody()));
Please or to participate in this conversation.