谷歌Android地图addMarker()非常缓慢加入400的标记时, [英] Android Google Map addMarker() very slow when adding 400 markers

查看:323
本文介绍了谷歌Android地图addMarker()非常缓慢加入400的标记时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您抽出时间来阅读这一点。

Thank you for taking the time to read this.

我在一个月前(14年8月29日)公布的一个应用程序的谷歌Play商店有关,这是不是与标志相同数量的问题。这个星期,我注意到当我去到我的应用程序,装载400标记到地图花了大约10-20秒对我的银河S5,并且有一小圈的默认地图标记图标的中间。在此之前,在地图上装载在不到一秒的时间。我还没有更新或更改我的应用程序。我猜谷歌更新了谷歌地图API和变化使得它更慢加载标记?出现这种情况给任何人?没有任何人有这方面的信息?

I published an app to the Google Play store about a month ago(08/29/14) and this wasn't a problem with the same amount of markers. This week, i've noticed when i went onto my app that loading the 400 markers to the map took about 10-20 seconds on my Galaxy S5 and that there is a small circle in the middle of the default map marker icons. Before this, the map loaded in less than a second. I haven't updated or changed my app. I'm guessing Google updated the Google Map API and the change made it much slower to load markers? Has this happened to anyone else? Does anyone else have information about this?

我的应用程序是免费的Play商店。您可以搜索NYS运河指南来找到它,如果你想看看它是如何缓慢的加载。

My app is available for free on the Play Store. You can search NYS Canal Guide to find it if you want to see how slow it loads.

该方法被调用的地图片段的onCreateView()在地图初始化后:

This method gets called in the onCreateView() of the map fragment after the map is initialized:

    private void addExistingMarkersToMap(){
    log("Adding existing markers to the map. poiAdapter size = " + poiAdapter.getCount());
    Marker marker;
    MarkerOptions markerOptions;

    for(MapMarker mapMarker : poiAdapter){
        if(markersNotFilteredOut(mapMarker)){
            markerOptions = mapMarker.getMarkerOptions();

            if(markerOptions != null && mapMarker != null){
                marker = mMap.addMarker(markerOptions);
                mapMarker.setMarker(marker);
            }
        }
    }
}

这是getMarkerOptions()在MapMarker类方法:

This is the getMarkerOptions() method on a MapMarker class:

public MarkerOptions getMarkerOptions() {
    return new MarkerOptions()
    .title(name)
    .position(new LatLng(lat, lng))
    .snippet(bodyOfWater + ", mile " + mile)
    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
}

完整的源$ C ​​$ c是在这里:github.com/olearyj234/NYS-Canal-Guide

The full source code is here: github.com/olearyj234/NYS-Canal-Guide

编辑:

**要,即慢加载标记时地图被初始化的一部分(因此也从一个导航标签交换和回到地图标签时)是具体的。移动地图或其他任何东西,当它不慢。

** To be specific, the only part that is slow is loading the markers when the map is being initialized(so also when switching from one navigation tab and back to the map tab). It isn't slow when moving the map or anything else.

下面是一些日志,上来:

Here are some logs that come up:

当屏幕被冻结为几秒钟(5-15),因为它的加载的标记,该日志被生产非常快。该位图的id继续递增一式,而标记加载时,它产生约这些日志400。这表明,它必须是相关的加载屏幕上的标记位图的一个问题。我使用的是默认的标志位。

While the screen is frozen for a few seconds(5-15) because its loading the markers, this log is being produced very fast. The bitmap id continues to increment by one and while the markers are loading, it produces about 400 of these logs. This shows that it has to be a problem related to loading the marker bitmaps on the screen. I'm using the default marker bitmap.

   10-01 15:45:07.222: D/skia(32108): GFXPNG PNG bitmap created width:16 height:32 bitmap id is 414

当应用程序被加载完所有标记到地图此日志就产生了。

This log is produced when the app is finished loading all the markers to the map.

10-01 15:51:09.402: I/Choreographer(8353): Skipped 1130 frames!  The application may be doing too much work on its main thread.

当应用程序被加载完所有标记到地图此日志产生14次。

This log is produced 14 times when the app is finished loading all the markers to the map.

10-01 15:59:13.882: I/dalvikvm-heap(8353): Grow heap (frag case) to 40.668MB for 4194320-byte allocation

编辑2:

我刚刚检查,看它会采取为code的某些行多久。我用 System.currentTimeMillis的(); ,以获得时间。该方法 addExistingMarkersToMap(),这是花了很长的行:标记= mMap.addMarker(markerOptions); 当添加所有400标记,花了54毫秒,平均每个标记。最小时间为34ms,最大为114ms。

I just checked to see how long it would take for certain lines of code. I used System.currentTimeMillis(); in order to get times. In the method addExistingMarkersToMap(), this is the line that took long: marker = mMap.addMarker(markerOptions); When adding all 400 markers, it took 54 ms on average for each marker. The min time was 34ms and the max was 114ms.

如果有任何你觉得我应该提供更多的信息,让我知道在评论。 谢谢!

If there's any more information you think i should provide, let me know in a comment. Thank you!

推荐答案

这似乎是谷歌地图API第2版引入了一个新的问题(貌似播放服务6更新之一),看到的#7174 更多信息(和请明星是

This appears to be a new problem introduced in Google Maps API v2 (looks like one of the Play Services 6 updates), see #7174 for more info (and please star it).

从问题中提供的信息,这个问题似乎是特定于使用默认标记的用色相的,例如:

From the info provided in the issue, the problem seems to be specific to using a default marker with a hue, e.g.:

BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)

有一些解决方法。最简单的就是没有提供一个色调(如果所有标记为红色是可以接受的):

There are some workarounds. Easiest is to not provide a hue (if all your markers being red is acceptable):

BitmapDescriptorFactory.defaultMarker()

或者使用自定义的可绘制:

Or use custom drawables:

BitmapDescriptorFactory.fromResource(R.drawable.map_marker)

我看到一个〜2000倍液使用减速带色调的默认标记时。我与自定义可绘制作为一个解决方案,就现在。

I see a ~2000 times slowdown when using the default marker with a hue. I'm going with the custom drawables as a solution for now.

这篇关于谷歌Android地图addMarker()非常缓慢加入400的标记时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆