dongzhao1930 2015-04-17 02:26
浏览 35

使用yii2-google-map-library从数据库显示多边形


i have problem when i'm trying to show polygon from database using yii2-google-maps-library. i've table tb_wilayah with field (id, label, lat, lng) and then i try to show the polygon on map with this code :

$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);

unfortunatelly i've error message 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

could someone help me? or if someone could provide a tutorial, that would be a real help.

  • 写回答

1条回答 默认 最新

  • doulachan8217 2018-08-23 08:43
    关注

    Thx for the above code. That pointed me in the right direction. This worked for me:

    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);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题