extranet/library/Scores/Streetview.php
2013-07-30 08:41:29 +00:00

98 lines
2.1 KiB
PHP

<?php
/**
* 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_Streetview
{
protected $url = 'http://maps.googleapis.com/maps/api/streetview?';
//Max size 640x640
protected $size = '640x640';
//GPS ou Adresse
protected $location = null;
//Defaut 90, Max 120, represents zoom, with smaller numbers indicating a higher level of zoom
protected $fov = 90;
//(default is 0) Specifies the up or down angle of the camera relative to the Street View vehicle
protected $pitch = 0;
//(optional) identifies your application for quota purposes
protected $key = null;
protected $sensor = 'false';
// Indicates the compass heading of the camera (0 to 360)
protected $heading = 0;
protected $nbImage = 8;
protected $extension = 'jpg';
public function __construct()
{
$this->size = '320x320';
}
public function setLocationGeo($lattitude, $longitude)
{
$this->location = $lattitude.','.$longitude;
}
public function setLocationTxt($adresse){}
public function setHeading($num)
{
$this->heading = $num;
}
public function getNumDeg()
{
$mark = array();
$deg = 360/$this->nbImage;
$i=$calc=0;
while ($calc<360) {
$mark[$i] = $calc;
$calc+=$deg;
$i++;
}
return $mark;
}
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)) ) {
$filename = $this->siret.'-'.$this->heading . '.' . $this->extension;
$body = $page['body'];
file_put_contents($this->path . DIRECTORY_SEPARATOR . $filename, $body);
}
}
public function pathImg()
{
$filename = $this->siret.'-'.$this->heading . '.' . $this->extension;
return $this->path . DIRECTORY_SEPARATOR . $filename;
}
}