1
votes

I am using guzzle to call to Street View Image API from my laravel application. I want to be able to retrieve the status code from my request as explained in the end of the docs.

I specifically want to catch the:

{
    "status" : "ZERO_RESULTS"
}

here is my Guzzle code from my controller (am including guzzle correctly in namespace). The address in the get call is generating a "Sorry we have no imagery here":

$client = new Client();
        $res = $client->get('https://maps.googleapis.com/maps/api/streetview?size=800x600&location=78.648401,14.194336&key=my-API-key&fov=120&heading=90');
        $res->getStatusCode();
        dd($res->getBody());

BUT. As u can see in the pic the meta-data is empty. When I dd the $res->getStatusCode(); it gives me a 200.

How do I catch the ZERO_RESULT ?

enter image description here

1

1 Answers

1
votes

Sir, please note that there are two different endpoints; one for metadata and one for image retrieval. You only used the image retrieval. Here is an example method checking if a given coordinate has an image

private function coordinateHasImage($coordinate)
{
    $client = new Client();
    $res = $client->get(  'https://maps.googleapis.com/maps/api/streetview/metadata?size=600x300&location=' . $coordinate . '&fov=90&heading=235&pitch=10&key=YOUR_KEY_HERE');
    return json_decode($res->getBody()->getContents())->status == "OK";
}