android google map v2 绘制 1k 圈性能问题

android google map v2 drawing 1k circles performance issue

我正在尝试在 google 地图 v2(大约 1k)上画很多圆圈。不幸的是,绘制所有圆圈时速度很慢,地图也很滞后。我在 Whosebug 上阅读了很多,但还没有找到解决方法。

圆圈表示 gps 路径(步行),因此在这里显示 1k 或 hundreads 点是有意义的(当然取决于缩放级别)。

我想我正在创建许多导致性能问题的对象:

 CircleOptions circleOptions = new CircleOptions();
        circleOptions.center(new LatLng(latitude, longitude)).clickable(false).strokeWidth(2).strokeColor(Color.BLACK).fillColor(colorInHex)
                .radius(0.7);
 Circle circle = googleMap.addCircle(circleOptions);

数据从房间数据库中检索

   repository.getByLatLngBounds(projection.northeast.latitude, projection.northeast.longitude, projection.southwest.latitude, projection.southwest.longitude, new callback() {

                    @Override
                    public void loaded(List<MyPoint> points) {
                        if (points != null && googleMap != null) {
                          // iterate and draw points with circle
                        }
             }
});

解释:

  1. 我无法减少圆圈的数量,因为我已经只定位了地图的可见范围
  2. 数据(圆的坐标)是从房间数据库中检索的,但实际上用不到 1 秒的时间就得到了结果(来自异步任务)
  3. 如果用户在地图上移动,我不会重绘所有点(我会跟踪所有绘图点,如果点已经绘制,我什么都不做)
  4. 我正在使用 android google 地图 v2
  5. 我没有尝试使用自定义可绘制对象(性能应该更差)。
  6. 问题不在于标记显示,而在于绘制点(因为我不想在这里绘制多边形)

benchmark test numbers : 1227 points take 10s for drawing 听起来很慢是吧?

在那种情况下提高性能的方法是什么?如有任何帮助,我们将不胜感激。

我终于找到了解决方法。我检查了大约快 12 倍的折线的性能。那么好吧,如果点数太多,画圈是不可能的。

所以我的想法是画一条折线,然后添加一个带点的图案。

  PolylineOptions polylineOptions = new PolylineOptions();
  polylineOptions.width(3);
  polylineOptions.color(Color.RED);
  for(MyPoint point : pointsToDraw){
     polylineOptions.add(new LatLng(point.getLatitude(), point.getLongitude()));
  }
  Polyline polyline = googleMap.addPolyline(entry.getValue());
  // the key is here with the pattern
  List<PatternItem> pattern = Arrays.asList(new Dot());
  polyline.setPattern(pattern);