Skip to content

Commit

Permalink
Few fix and enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
defro committed Feb 28, 2021
1 parent 002409c commit 95bba59
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
/composer.lock
/composer.phar

# PHPUnit
/.phpunit.result.cache

# Example
/example/.env
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $metadata = $api->getMetadata('Forbidden City, Beijing, China');
```

# Customize it
A lot of parameters is ready to be overwrite. _This example contains values set by default._
A lot of parameters is ready to be overwritten. _This example contains values set by default._
```php
$api
->setImageWidth(600)
Expand Down
24 changes: 10 additions & 14 deletions example/index.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?php
/**
* Test it with Dockerfile provided:
* $ docker run -it --rm --name google-street-view -v "$(pwd)/example":/application/example -v "$(pwd)/src":/application/src -p 8080:80 google-street-view
* Open your browser and go to : http://localhost:8080
*
* Bonus: launch example wth CLI interpreter
* $ docker run -it --rm --name google-street-view -v "$(pwd)/example":/application/example -v "$(pwd)/src":/application/src google-street-view php example/index.php
* Test it with Dockerfile provided, read documentation: docs/docker.md
*/

ini_set('display_errors', '1');
error_reporting(E_ALL);

require_once __DIR__.'/../vendor/autoload.php';

use Defro\Google\StreetView\Api;

/**
* You can customize this value to test it.
*/
Expand All @@ -26,8 +24,6 @@
: $locationName;
}

use Defro\Google\StreetView\Api;

if (file_exists(__DIR__.'/.env')) {
$dotEnv = new \Dotenv\Dotenv(__DIR__);
$dotEnv->load();
Expand All @@ -54,13 +50,13 @@
$imgUrl = $streetView->getImageUrlByLocation($locationName);
$searchUrl = 'https://www.google.com/maps/search/?api=1&query=';
$searchUrl .= urlencode($locationName);
$print['Display image url by location name'] = [
$print['Image url by location name'] = [
'<img src="'.$imgUrl.'" alt="'.$locationName.'" />',
'Image URL : <a href="'.$imgUrl.'">'.$imgUrl.'</a>',
'Search URL : <a href="'.$searchUrl.'">'.$searchUrl.'</a>',
];
} catch (Exception $e) {
$print['Display image url by location name'] = 'Error when get image url by location name : '.$e->getMessage();
$print['Image url by location name'] = 'Error when get image url by location name : '.$e->getMessage();
}

try {
Expand All @@ -77,26 +73,26 @@
$imgUrl = $streetView->getImageUrlByPanoramaId($metadata['panoramaId']);
$searchUrl = 'https://www.google.com/maps/@?api=1&map_action=pano&pano=';
$searchUrl .= $metadata['panoramaId'];
$print['Display image url by panorama ID'] = [
$print['Image url by panorama ID'] = [
'<img src="'.$imgUrl.'" alt="'.$locationName.'" />',
'Image URL : <a href="'.$imgUrl.'">'.$imgUrl.'</a>',
'Search URL : <a href="'.$searchUrl.'">'.$searchUrl.'</a>',
];
} catch (Exception $e) {
$print['Display image url by panorama ID'] = 'Error when get image url by panorama ID : '.$e->getMessage();
$print['Image url by panorama ID'] = 'Error when get image url by panorama ID : '.$e->getMessage();
}

try {
$imgUrl = $streetView->getImageUrlByLatitudeAndLongitude($metadata['lat'], $metadata['lng']);
$searchUrl = 'https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=';
$searchUrl .= $metadata['lat'].','.$metadata['lng'];
$print['Display image url by latitude and longitude'] = [
$print['Image url by latitude and longitude'] = [
'<img src="'.$imgUrl.'" alt="'.$locationName.'" />',
'Image URL : <a href="'.$imgUrl.'">'.$imgUrl.'</a>',
'Search URL : <a href="'.$searchUrl.'">'.$searchUrl.'</a>',
];
} catch (Exception $e) {
$print['Display image url by latitude and longitude'] = 'Error when get image url by latitude and longitude : '.$e->getMessage();
$print['Image url by latitude and longitude'] = 'Error when get image url by latitude and longitude : '.$e->getMessage();
}

if (PHP_SAPI === 'cli') {
Expand Down
21 changes: 13 additions & 8 deletions example/index.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title>Google street view API PHP example</title>
<link rel="icon" type="image/png" href="favicon.png"/>
Expand All @@ -9,21 +9,20 @@
<nav class="light-blue lighten-1" role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" href="#" class="brand-logo">
Google street view example
Google street view example script
</a>
</div>
</nav>

<div class="section no-pad-bot" id="index-banner">
<div class="container">
<div class="row">
<div class="col s12">
<ul class="tabs" id="tabs">
<li class="tab col s3">
<li class="tab col s6">
<a href="#tab-result">Result</a>
</li>
<li class="tab col s3">
<a href="#tab-form">Test a location</a>
<li class="tab col s6">
<a href="#tab-form">Try another location</a>
</li>
</ul>
</div>
Expand All @@ -32,7 +31,13 @@
<form class="col s12" action="#" method="get">
<div class="row">
<div class="input-field col s12">
<input placeholder="Forbidden City, Beijing, China" id="location_name" name="location_name" type="text" class="validate" value="{{ locationName }}">
<input type="text"
placeholder="Forbidden City, Beijing, China"
value="{{ locationName }}"
id="location_name"
name="location_name"
class="validate"
/>
<label for="location_name">Location name</label>
</div>
</div>
Expand All @@ -48,7 +53,7 @@
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script type="text/javascript">
var instance = M.Tabs.init(document.getElementById('tabs'));
const instance = M.Tabs.init(document.getElementById('tabs'));
</script>
</body>
</html>

0 comments on commit 95bba59

Please sign in to comment.