Passed
Push — master ( 6f7cd5...976572 )
by
unknown
02:05
created

example.php (1 issue)

Labels
Severity
1
<?php
2
# php -S localhost:2626
3
4
ini_set('display_errors', true);
0 ignored issues
show
true of type true is incompatible with the type string expected by parameter $newvalue of ini_set(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

4
ini_set('display_errors', /** @scrutinizer ignore-type */ true);
Loading history...
5
error_reporting(E_ALL);
6
7
require_once __DIR__ . '/vendor/autoload.php';
8
9
$dotEnv = new \Dotenv\Dotenv(__DIR__);
10
$dotEnv->load();
11
12
$apiKey = getenv('GOOGLE_API_KEY');
13
if (!$apiKey || empty($apiKey)) {
14
    throw new RuntimeException('No Google api key found.');
15
}
16
17
$client = new \GuzzleHttp\Client();
18
19
$streetView = new \Defro\Google\StreetView\Api($client);
20
$streetView->setApiKey($apiKey);
21
22
$locationName = 'Sydney Opera House, Sydney, Australia';
23
//$locationName = 'A place which not exists';
24
25
echo '<p>Handle location : ' . $locationName . '</p>';
26
27
try {
28
    $metadata = $streetView->getMetadata($locationName);
29
    echo '<pre>';print_r($metadata);echo '</pre>';
30
}
31
catch (Exception $e) {
32
    die('Error when get metadata : ' . $e->getMessage());
33
}
34
35
$streetView->setImageWidth(400)->setImageHeight(400);
36
37
echo '<ul>';
38
39
try {
40
    $imgUrl = $streetView->getImageUrlByLocation($locationName);
41
    echo PHP_EOL . '<li>By location name: <img src="' . $imgUrl . '" /></li>';
42
}
43
catch (Exception $e) {
44
    die('Error when get image url by location name : ' . $e->getMessage());
45
}
46
47
try {
48
    $imgUrl = $streetView->getImageUrlByPanoramaId($metadata['panoramaId']);
49
    echo PHP_EOL . '<li>By panorama ID: <img src="' . $imgUrl . '" /></li>';
50
}
51
catch (Exception $e) {
52
    die('Error when get image url by panorama ID : ' . $e->getMessage());
53
}
54
55
try {
56
    $imgUrl = $streetView->getImageUrlByLatitudeAndLongitude($metadata['lat'], $metadata['lng']);
57
    echo PHP_EOL . '<li>By latitude & longitude: <img src="' . $imgUrl . '" /></li>';
58
}
59
catch (Exception $e) {
60
    die('Error when get image url by latitude and longitude : '.$e->getMessage());
61
}
62
63
echo '</ul>' . PHP_EOL;
64