Files
ledstar_laravel/app/Http/Controllers/MapController.php
T
2026-05-15 18:39:04 +03:00

54 lines
1.2 KiB
PHP

<?PHP
namespace App\Http\Controllers;
use App\Models\ORM\Place;
class MapController extends Controller
{
/**
* https://api-maps.yandex.ru/2.1/?lang=ru_RU&amp;apikey=<ваш API-ключ>
*/
private string $yandex_url = "https://api-maps.yandex.ru/2.1";
private string $yandex_key = "9ea0bde8-b886-4620-9eab-c354727b634c";
private array $apiParams;
public function index(int $id)
{
$this->apiParams = array(
"apikey" => $this->yandex_key,
"lang" =>"ru_RU",
);
$apiCall = $this->createApiCall();
return $this->render('yandex_map')
->with('apiCall', $apiCall)
->with('yandex_maps_id', $id);
}
public function getPlace(int $id)
{
$place = Place::find($id);
[ $x, $y ] = explode("|",$place->Gps);
return response()->json([
'x' => $x, 'y' => $y
]);
}
private function createApiCall(): string
{
$tmp = [];
foreach($this->apiParams as $k => $v) {
$tmp[] = sprintf("%s=%s", $k, $v);
}
return sprintf("%s/?%s", $this->yandex_url, implode("&", $tmp));
}
}
?>