Added Yandex Maps

This commit is contained in:
amikhaylov
2026-05-15 18:39:04 +03:00
parent 443a745029
commit 0c06d83b0b
5 changed files with 104 additions and 3 deletions
@@ -0,0 +1,11 @@
<?php
namespace App\Http\Controllers\Interfaces;
interface IController
{
/**
* @return mixed
*/
public function indexAction();
}
+53
View File
@@ -0,0 +1,53 @@
<?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));
}
}
?>