0


当我尝试使用yii2-google-maps-library. 我有一个tb_wilayah带有字段的表格,(id, label, lat, lng)然后我尝试使用以下代码在地图上显示多边形:

$data = AreaWilayah::find()->all();
    $paths = [];
    foreach ($data as $value){
        $koord = new LatLng([
            'lat' => $value->lat,
            'lng' => $value->lng
        ]);
        array_push($paths, $koord);
    }
    $coords = [$paths];
    $polygon = new Polygon([
        'paths' => $coords
    ]);
    $map->addOverlay($polygon);

不幸的是我有错误信息Argument 1 passed to dosamigos\google\maps\overlays\PolygonOptions::addCoord() must be an instance of dosamigos\google\maps\LatLng, array given, called in C:\xampp\htdocs\project\vendor\2amigos\yii2-google-maps-library\overlays\PolygonOptions.php on line 120 and defined

有人可以帮助我吗?或者如果有人可以提供教程,那将是一个真正的帮助。

4

1 回答 1

0

谢谢上面的代码。这为我指明了正确的方向。这对我有用:

foreach ($ismalls as $mall) {
    $poly_json = json_decode($mall->polygonpoints, true);
    $coords = [];
    //echo print_r($poly_json);
    foreach ($poly_json as $points) {
        $koord = new LatLng([
            'lat' => $points[1],
            'lng' => $points[0]
        ]);
        array_push($coords, $koord);
    }
   $polygon = new Polygon([
        'paths' => $coords
    ]);

    // Add a shared info window
    $polygon->attachInfoWindow(new InfoWindow([
        'content' => '<p>'.$mall->display_name.'</p>'
        ]));

    // Add it now to the map
    $map->addOverlay($polygon);
}
于 2018-08-23T08:43:57.447 回答