Php Yii2地图群集挑战,从数据库读取坐标

Php Yii2地图群集挑战,从数据库读取坐标,php,json,yii2,Php,Json,Yii2,我正在从事一个使用Yii2框架的项目。项目应显示地图并提供点数的集合,当进一步缩放时,点的位置将显示一个标签,该标签似乎与示例数据配合良好 然而,当从数据库检索到应该提供坐标和标签的数据时,有一些错误我已经徒劳地纠正了。我张贴的样本数据信息和自定义代码,这是抛出的帮助错误 <?php $map = new Map([ 'center' => new LatLng(['lat' => 0.0236, 'lng' => 37.9062]), // Center

我正在从事一个使用Yii2框架的项目。项目应显示地图并提供点数的集合,当进一步缩放时,点的位置将显示一个标签,该标签似乎与示例数据配合良好

然而,当从数据库检索到应该提供坐标和标签的数据时,有一些错误我已经徒劳地纠正了。我张贴的样本数据信息和自定义代码,这是抛出的帮助错误

    <?php
$map = new Map([
    'center' => new LatLng(['lat' => 0.0236, 'lng' => 37.9062]), // Center of Kenya
    'zoom'   => 10,
]);

 $cities = [
    'Jakech   fishing group'    => new LatLng(['lat' => -0.0875882, 'lng' => 34.7826236]),
    'Waste gager self help group'  => new LatLng(['lat' => -0.2743137, 'lng' => 36.0484026]),
    'Upepo self help group'  => new LatLng(['lat' => -0.270685, 'lng' => 36.0490248]),
    'ABC' => new LatLng(['lat' => -0.2707479, 'lng' => 36.0490439]),
    'DOBICK'  => new LatLng(['lat' => -3.9394018, 'lng' => 39.6733605]),
    'OTEGA'        => new LatLng(['lat' => -0.2707093, 'lng' => 36.0491224]),
    'FRISCK ' => new LatLng(['lat' => -1.2871144, 'lng' => 36.7476729]),
    'Jamia   Investment'     => new LatLng(['lat' => -0.2303193, 'lng' => 35.9919988]),
    ' Muhia   Group  '     => new LatLng(['lat' => -0.7906807, 'lng' => 36.4308399]),
    'WEPK'  => new LatLng(['lat' => -4.0926557, 'lng' => 39.6344806]),
    ' Sawte youth group'  => new LatLng(['lat' => -1.2871353 , 'lng' => 36.7476734 ]),
    'Eyub Kalo Group'      => new LatLng(['lat' => -0.7552372, 'lng' => 36.48371078]),
    'ASB juba'  => new LatLng(['lat' => 0.00285387, 'lng' =>34.96531963]),
]; 

foreach ($cities as $city => $lat_lng) {
    $marker = new Marker([
        'position'  => $lat_lng,
        'title'     => $city,
        'clickable' => true,
    ]);

    $marker->attachInfoWindow(new InfoWindow(['content' => "<strong>{$city}</strong>"]));
    $map->addOverlay($marker);
}

$map->center = $map->getMarkersCenterCoordinates();
$map->zoom = $map->getMarkersFittingZoom() - 1;
?>

下面是从数据库获取数据的代码。好的,数据库表称为mytable,它有字段locoordinates和Name_optional,locoordinates列有纬度和经度,而Name_optional只有标签。我的目标是显示数据库中的详细信息,以显示在地图上,下面是我的代码,它不起作用。该地图由yii2 marker clusterer插件显示,该插件可从以下站点获得


我将感谢你在这方面的帮助。多谢各位

    <?php

$map = new Map([
    'center' => new LatLng(['lat' => 0.0236, 'lng' => 37.9062]), // Center of Kenya
    'zoom'   => 12,
]);

$list = Yii::$app->db->createCommand('SELECT Name_optional,locoordinates FROM mytable ')->queryAll();
foreach ($list as $mall) {
    $dumpname = $list['Name_optional'];
    $latlong = explode(" ", $list['locoordinates']); 
    $llatt = $latlong[0]; // piece1
    $llong = $latlong[1]; // piece2
    $cordss = array($dumpname,$llatt,$llong);
    
    $poly_json = json_decode($cordss, true);
    $coords = [];    
//  foreach($list as $slist){

//}
 
foreach ($cities as $city => $lat_lng) {
    $marker = new Marker([
        'position'  => $lat_lng,
        'title'     => $city,
        'clickable' => true,
    ]);

    $marker->attachInfoWindow(new InfoWindow(['content' => "<strong>{$city}</strong>"]));
    $map->addOverlay($marker);
}

$map->center = $map->getMarkersCenterCoordinates();
$map->zoom = $map->getMarkersFittingZoom() -8;
?>


        <?= $map->display(); } ?>