196 lines
3.3 KiB
PHP
196 lines
3.3 KiB
PHP
<?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';
|
|
|
|
/**
|
|
* Path where files are stored
|
|
*/
|
|
protected $path = '';
|
|
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $siret;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function __construct($siret)
|
|
{
|
|
$this->size = '320x320';
|
|
|
|
$this->siret = $siret;
|
|
|
|
$c = Zend_Registry::get('config');
|
|
$this->path = realpath($c->profil->path->data).'/google/streetview';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @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()
|
|
{
|
|
Zend_Registry::get('firebug')->info('URL = '.$this->url);
|
|
try {
|
|
$client = new Zend_Http_Client($url);
|
|
$client->setStream();
|
|
$response = $client->request('GET');
|
|
if ( $response->isSuccessful() ) {
|
|
copy($response->getStreamName(), $this->pathImg());
|
|
}
|
|
} catch (Zend_Http_Client_Exception $e) {}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function pathImg()
|
|
{
|
|
$filename = $this->siret.'-'.$this->heading . '.' . $this->extension;
|
|
return $this->path . DIRECTORY_SEPARATOR . $filename;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function display()
|
|
{
|
|
$this->url = $this->urlImg();
|
|
$file = $this->pathImg();
|
|
Zend_Registry::get('firebug')->info('Filename = '.$file);
|
|
if ( !file_exists($file) ) {
|
|
$this->getImg();
|
|
}
|
|
|
|
return basename($file);
|
|
}
|
|
|
|
} |