yii2 da map ishlash

0 ovoz
26 marta ko‘rilgan
so‘radi 12 yanvar user_best (125 bal)
ko‘rsatildi 13 yanvar Saidolim
Qanday qilib yii2 da xarita bn ishlasa bo'ladi
izoh qoldirdi 12 yanvar user_best (125 bal)
ko‘rsatildi 13 yanvar Saidolim
Iloji bo'lsa kodini tashlab yuborsangiz
izoh qoldirdi 12 yanvar user_best (125 bal)
ko‘rsatildi 13 yanvar Saidolim
men xaritani kordinatalarini belgilab ololmayabman

2 Javoblar

+2 ovoz
javob berdi 12 yanvar MrHope (662 bal)
use yii\helpers\ArrayHelper;
$array = [
    ['id' => '123''name' => 'aaa'],
    ['id' => '124''name' => 'bbb'],
    ['id' => '345''name' => 'ccc'],
);
$items = ArrayHelper::map($array, 'id', 'name');
0 ovoz
javob berdi 6 kun avval SpecialistX (248 bal)

MapController

<?php namespace frontend\controllers;
use common\models\Shop;
class MapController extends \yii\web\Controller
{
    public $layout = 'empty';
    public function actionIndex($id)
    {
        $shop = Shop::findOne(['status' => 1, 'id' => $id]);
        return $this->render('index', [
            'shop' => $shop
        ]);
    }
}
izoh qoldirdi 6 kun avval SpecialistX (248 bal)
index.php (view)

<?php
use dosamigos\google\maps\LatLng;
use dosamigos\google\maps\Map;
use dosamigos\google\maps\overlays\InfoWindow;
use dosamigos\google\maps\overlays\Marker;
if ($shop->info->lat != "" && $shop->info->lng != "") {
    $coord = new LatLng(['lat' => $shop->info->lat, 'lng' => $shop->info->lng]); //bu yerda DB dan latitude va longitude chaqirib olinyabdi, siz buni oodiy koordinata ko'rinishida yozib ketsangiz ham bo'ladi
    $map = new Map([
        'center' => $coord, //bu yerda koordinatalar kiritlgan
        'zoom' => 14, //14 marta yaqinlashtirib ko'ratyabdi
    ]);
    $map->width = '100%'; //eniga ekranni to'liq egallaydi
    $map->height = '500'; //bo'yiga esa 500px
    $marker = new Marker([
        'position' => $coord,
        'title' => $shop->name,
    ]);
    $marker->attachInfoWindow(
        new InfoWindow([
            'content' => '<p>' . $shop->name . '</p>'
        ])
    );
    $map->addOverlay($marker);
    echo $map->display();
}

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...