【问题标题】:How can I draw Polygons on google-maps with coordinates from Array如何使用数组中的坐标在谷歌地图上绘制多边形
【发布时间】:2019-07-26 11:24:04
【问题描述】:

我从 firestore 检索坐标并将它们保存在一个 latlng 列表数组中。

然后使用 for 循环,我将列表数组中的元素填充到 PolygonOptions 变量中。 调试显示所有数据都在应有的位置,但无法在地图上绘制多边形

这是我尝试过的

 private void DrawPolygon(List<LatLng> array) {

    int length = array.size();
    if(length == 0)
    {
        // Do whatever you like then get out. Do not run the following.
        return;
    } 
    PolygonOptions poly = new PolygonOptions();
     for (int i = 0; i < length; i++) {
            LatLng latLong = new LatLng(array.get(i).latitude,
                    array.get(i).longitude);
            poly.add(latLong);
        }
        Polygon polygon = mMap.addPolygon(poly);

`

应用程序没有显示任何错误

【问题讨论】:

    标签: java android


    【解决方案1】:

    使用

    poly.strokeColor(ContextCompat.getColor(this,android.R.color.holo_orange_dark));
    
    poly.fillColor(ContextCompat.getColor(this,android.R.color.holo_orange_light));
    
    
    

    【讨论】:

    • 它仍然没有画任何东西
    • 您在 mMap.addPolygon(poly); 之前添加了这些行。我能问你为什么要返回 mMap.addPolygon(poly)
    • 从我发布的代码中,您可以看到 poly 填充了来自周界数组的坐标。所以返回 mMap.addPolygon(poly) 应该在地图上绘制多边形
    • 如果我像往常一样用polygonOptions().add ( new latlng .. 手动添加每个坐标,上面的sn-p就可以了。但我不能这样做,因为它们存储在 firestore 数据库中,并被检索并存储在一个数组中,该数组作为周长传递给 DrawPolygon 方法
    • 返回值后是否更新了地图相机
    猜你喜欢
    • 2016-07-22
    • 2017-12-16
    • 1970-01-01
    • 2014-04-02
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多