Fixed printing informations about nearest traficar car. Increased size of printed image from 300 to 370px.
This commit is contained in:
@@ -13,7 +13,9 @@ class Traficar
|
||||
{
|
||||
|
||||
private $homeCoords = ['lat' => 54.417475, 'lng' => 18.481913];
|
||||
private $staticMapsKey = 'AIzaSyBPb9wXT2BcK8EH_3FFWVc2MLuDprj7YXw';
|
||||
|
||||
//dystans w kilometrach w którym auta brane są pod uwagę
|
||||
const CLOSEST_DISTANCE = 2;
|
||||
|
||||
/**
|
||||
* @param $lat1
|
||||
@@ -34,7 +36,29 @@ class Traficar
|
||||
}
|
||||
|
||||
|
||||
public function nearestCar()
|
||||
/**
|
||||
* pobiera informacje o najbliższym trafficarze względem punktu podanego jako domowy i zwraca Sformatowane
|
||||
* informacje na jego temat lub jesli nie ma auta to podaje informację że nie ma dostępnego.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function nearestCarText()
|
||||
{
|
||||
$info = $this->nearestCarInfo();
|
||||
$formatedInfo = 'Brak aut w promieniu ' . self::CLOSEST_DISTANCE . 'km od domu.';
|
||||
if ($info['car'] != []) {
|
||||
$formatedInfo = "Najbliższy traficar:\n" .
|
||||
'Model: ' . $info['car']['model'] . "\n" .
|
||||
'Numer boczny: ' . $info['car']['orderNumber'] . "\n" .
|
||||
'Rejestracja: ' . $info['car']['regNumber'] . "\n" .
|
||||
'Lokalizacja: ' . $info['car']['location'] . "\n" .
|
||||
'Odległość: ' . $info['distance'] . "km\n";
|
||||
}
|
||||
return $formatedInfo;
|
||||
}
|
||||
|
||||
|
||||
public function nearestCarInfo()
|
||||
{
|
||||
$trafcarData = json_decode(file_get_contents('https://api.traficar.pl/eaw-rest-api/car?shapeId=5'), 1);
|
||||
$closestCar = [];
|
||||
@@ -42,19 +66,11 @@ class Traficar
|
||||
foreach ($trafcarData['cars'] as $car) {
|
||||
|
||||
$distance = $this->distance($this->homeCoords['lat'], $this->homeCoords['lng'], $car['latitude'], $car['longitude']);
|
||||
if ($distance < $closestDistance) {
|
||||
if ($distance < self::CLOSEST_DISTANCE && $distance < $closestDistance) {
|
||||
$closestDistance = $distance;
|
||||
$closestCar = $car;
|
||||
}
|
||||
}
|
||||
|
||||
// $imgNoKey = "https://maps.googleapis.com/maps/api/staticmap?center=" . $latHome . "," . $lngHome . "&size=300x300&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0x000000%7C" . $closestCar['latitude'] . "," . $closestCar['longitude'];
|
||||
// $img = "https://maps.googleapis.com/maps/api/staticmap?center=" . $this->homeCoords['lat'] . "," . $this->homeCoords['lng'] . "&size=300x300&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0x000000%7C" . $closestCar['latitude'] . "," . $closestCar['longitude'] . '&key=' . $this->staticMapsKey;
|
||||
// $tmpFile = storage_path() . '/traficar_map.png';
|
||||
// file_put_contents($tmpFile, file_get_contents($img));
|
||||
|
||||
|
||||
return ['car' => $closestCar, 'distance' => round($closestDistance, 2),];
|
||||
// 'imageName' => $tmpFile];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user