1

我正在使用 Skobbler Map 开发一个 Android 应用程序。

在我的应用程序中,我想显示许多自定义注释(png 引脚)。注释数量超过 500 个,并且 pin 图像在不同情况下会发生变化。我可以添加自定义注释,但在渲染注释时应用程序至少 10 秒无响应(请注意,添加注释需要不到一秒,但渲染大约需要 10 秒 - 手机有 3GB RAM) .

这是相关代码

private void addAnnotations(List<Item> itemList) {
    for (Item item : itemList) {
        int itemId = item.getItemId();
        SKAnnotation annotation = new SKAnnotation(itemId);
        annotation.setLocation(new SKCoordinate(item.getLatitude(), item.getLongitude()));
        //annotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_RED);

        SKAnnotationView annotationView = new SKAnnotationView();
        RelativeLayout customView = (RelativeLayout) ((LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
                       R.layout.layout_custom_pin, null, false);
        annotationView.setView(customView);
        annotationView.setReuseIdentifierWithId("cat." + item.getCategoryId());
        annotation.setAnnotationView(annotationView);

        mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE);
    }
}

如果我最初在上面的代码中创建“customView”并将其存储在成员变量中并重用它,那么结果也是一样的。

另请注意,如果我通过使用预定义注释类型调用 setAnnotationType 来使用普通引脚,它会非常快。Skobbler 建议使用与我相同的 id 的 setReuseIdentifierWithId,我不确定如何以及在何处使用该方法。请注意,在我的情况下,“item.getCategoryId()”为列表中的所有项目返回相同的值。

有人可以帮忙吗?

4

1 回答 1

1

我曾经遇到过这个问题。但是使用 SDK 3.0.3(Skobbler 团队的最新版本),我设法加载了注释。但是Android Monitor上会有一个警告。所以我把这个函数移到了一个带有进度条的 AsyncTask 中。它工作得更好。大约2秒?并且没有警告信息。

于 2017-09-22T06:51:51.937 回答