New StreeView class to store image on our filesystem
This commit is contained in:
parent
3658513eed
commit
d0b5423c7a
176
library/Scores/Google/Streetview.php
Normal file
176
library/Scores/Google/Streetview.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* https://developers.google.com/maps/documentation/streetview/
|
||||
* Image de 640x640 max
|
||||
* Heading 0 à 360
|
||||
* 0, 45, 90, 135, 180, 225, 270, 315
|
||||
* Récup de chaque image enregistré SIRET-DEG
|
||||
*/
|
||||
class Scores_Google_Streetview
|
||||
{
|
||||
/**
|
||||
* Service URL
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'http://maps.googleapis.com/maps/api/streetview?';
|
||||
|
||||
/**
|
||||
* Max size 640x640
|
||||
* @var string
|
||||
*/
|
||||
protected $size = '640x640';
|
||||
|
||||
/**
|
||||
* GPS ou Adresse
|
||||
* @var strign
|
||||
*/
|
||||
protected $location = null;
|
||||
|
||||
/**
|
||||
* Defaut 90, Max 120, represents zoom, with smaller numbers indicating a higher level of zoom
|
||||
* @var unknown
|
||||
*/
|
||||
protected $fov = 90;
|
||||
|
||||
/**
|
||||
* (default is 0) Specifies the up or down angle of the camera relative to the Street View vehicle
|
||||
* @var unknown
|
||||
*/
|
||||
protected $pitch = 0;
|
||||
|
||||
/**
|
||||
* (optional) identifies your application for quota purposes
|
||||
* @var string
|
||||
*/
|
||||
protected $key = null;
|
||||
|
||||
/**
|
||||
* always false
|
||||
* @var string
|
||||
*/
|
||||
protected $sensor = 'false';
|
||||
|
||||
/**
|
||||
* Indicates the compass heading of the camera (0 to 360)
|
||||
*/
|
||||
protected $heading = 0;
|
||||
|
||||
/**
|
||||
* Number of image by the circle (360°)
|
||||
* @var int
|
||||
*/
|
||||
protected $nbImage = 8;
|
||||
|
||||
/**
|
||||
* File extension
|
||||
* @var string
|
||||
*/
|
||||
protected $extension = 'jpg';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->size = '320x320';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param unknown $lattitude
|
||||
* @param unknown $longitude
|
||||
*/
|
||||
public function setLocationGeo($lattitude, $longitude)
|
||||
{
|
||||
$this->location = $lattitude.','.$longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param unknown $adresse
|
||||
*/
|
||||
public function setLocationTxt($adresse){}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param unknown $num
|
||||
*/
|
||||
public function setHeading($num)
|
||||
{
|
||||
$this->heading = $num;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return multitype:number
|
||||
*/
|
||||
public function getNumDeg()
|
||||
{
|
||||
$mark = array();
|
||||
$deg = 360/$this->nbImage;
|
||||
$i=$calc=0;
|
||||
while ($calc<360) {
|
||||
$mark[$i] = $calc;
|
||||
$calc+=$deg;
|
||||
$i++;
|
||||
}
|
||||
return $mark;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function urlImg()
|
||||
{
|
||||
$url = '';
|
||||
|
||||
$params = array( 'size', 'location', 'fov', 'pitch', 'sensor', 'heading' );
|
||||
foreach ($params as $param) {
|
||||
if ( $this->{$param} !== null ) {
|
||||
$url.= '&'.$param.'='. $this->{$param};
|
||||
}
|
||||
}
|
||||
|
||||
return $this->url . substr($url,1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getImg()
|
||||
{
|
||||
require_once 'common/curl.php';
|
||||
$page = getUrl($this->url, '', '', '', false);
|
||||
|
||||
if ( !in_array($page['code'], array(400, 408, 403)) ) {
|
||||
$body = $page['body'];
|
||||
file_put_contents($this->pathImg(), $body);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function pathImg()
|
||||
{
|
||||
$filename = $this->siret.'-'.$this->heading . '.' . $this->extension;
|
||||
return $this->path . DIRECTORY_SEPARATOR . $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display()
|
||||
{
|
||||
$file = $this->pathImg();
|
||||
if ( !file_exists($file) ) {
|
||||
$this->getImg();
|
||||
}
|
||||
|
||||
return basename($file);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user