gpt4 book ai didi

android - 仅加载我所在位置周围的标记 Google Map v2 Android

转载 作者:行者123 更新时间:2023-11-29 21:32:33 26 4
gpt4 key购买 nike

我在 Android 中的 Google map v2 上加载了很多标记(1700 个或更多)。我想减少创建此 map 所使用的内存量,因为它似乎是 FC my 2.3 Droid。我只想在可见屏幕区域内添加点。

我查看了 Google Maps Extension 并看到了这个:

map.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true));

但是我的 for 循环将所有标记添加到 map 中。我如何设置它并仅按此方法添加我的标记?

这是我的 for 循环添加标记:

int nsize = visibleMarkers.size();
for (int i = 0; i < nsize; i++) {
MapMarkers marks = new MapMarkers();
String title = visibleMarkers.valueAt(i).getTitle();
String desc = visibleMarkers.valueAt(i).getDesc();
Float latitude = visibleMarkers.valueAt(i).getLat();
Float longitude = visibleMarkers.valueAt(i).getLon();

m = map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(title)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.snotel_marker)));

marks.setTitle(title);
marks.setDesc(desc);

markerInfo.put(m, marks);

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {

MapMarkers markInfo = markerInfo.get(marker);

Intent i = new Intent(MainActivity.this,
MarkerInformation.class);
i.putExtra("name", markInfo.getTitle()).putExtra(
"description", markInfo.getDesc());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

}

});
}

如何仅在显示屏幕区域时添加它们。这会减少我设备上的资源使用吗?

编辑:::这是 logcat 问题

10-01 10:59:41.590: D/dalvikvm(6488): GC_FOR_MALLOC freed <1K, 55% free 10009K/21895K, external 2433K/2688K, paused 94ms
10-01 10:59:41.691: D/dalvikvm(6488): GC_FOR_MALLOC freed 128K, 55% free 9913K/21895K, external 2433K/2688K, paused 72ms
10-01 10:59:41.793: D/dalvikvm(6488): GC_FOR_MALLOC freed 62K, 55% free 9973K/21895K, external 2433K/2688K, paused 83ms
10-01 10:59:41.910: D/dalvikvm(6488): GC_FOR_MALLOC freed 65K, 55% free 10026K/21895K, external 2433K/2688K, paused 74ms
10-01 10:59:41.988: D/dalvikvm(6488): GC_FOR_MALLOC freed 0K, 54% free 10085K/21895K, external 2433K/2688K, paused 72ms
10-01 10:59:41.988: I/dalvikvm-heap(6488): Grow heap (frag case) to 14.703MB for 60434-byte allocation
10-01 10:59:42.082: D/dalvikvm(6488): GC_FOR_MALLOC freed 0K, 54% free 10144K/21959K, external 2433K/2688K, paused 82ms
10-01 10:59:42.199: D/dalvikvm(6488): GC_FOR_MALLOC freed 138K, 55% free 10043K/21959K, external 2433K/2688K, paused 82ms
10-01 10:59:42.207: I/dalvikvm-heap(6488): Grow heap (frag case) to 14.762MB for 164912-byte allocation
10-01 10:59:42.277: D/dalvikvm(6488): GC_FOR_MALLOC freed 8K, 54% free 10196K/22151K, external 2433K/2688K, paused 68ms
10-01 10:59:42.730: D/dalvikvm(6488): GC_FOR_MALLOC freed 509K, 55% free 10017K/22151K, external 2433K/2688K, paused 72ms
10-01 10:59:42.879: D/dalvikvm(6488): GC_FOR_MALLOC freed 364K, 55% free 10066K/22151K, external 2433K/2688K, paused 78ms
10-01 10:59:42.988: D/dalvikvm(6488): GC_FOR_MALLOC freed 39K, 55% free 10117K/22151K, external 2433K/2688K, paused 82ms
10-01 10:59:42.988: I/dalvikvm-heap(6488): Forcing collection of SoftReferences for 201280-byte allocation
10-01 10:59:43.082: D/dalvikvm(6488): GC_FOR_MALLOC freed 8K, 55% free 10108K/22151K, external 2433K/2688K, paused 86ms
10-01 10:59:43.082: E/dalvikvm-heap(6488): Out of memory on a 201280-byte allocation.
10-01 10:59:43.082: I/dalvikvm(6488): "vts_com.jasonflaherty.snoteldata" prio=5 tid=10 RUNNABLE
10-01 10:59:43.082: I/dalvikvm(6488): | group="main" sCount=0 dsCount=0 obj=0x405c8fe0 self=0x1c1ec0
10-01 10:59:43.082: I/dalvikvm(6488): | sysTid=6533 nice=10 sched=0/0 cgrp=bg_non_interactive handle=1628832
10-01 10:59:43.082: I/dalvikvm(6488): at maps.ao.d.a((null):~-1)
10-01 10:59:43.082: I/dalvikvm(6488): at maps.i.cu.a((null):-1)
10-01 10:59:43.082: I/dalvikvm(6488): at maps.k.ah.a((null):-1)
10-01 10:59:43.082: I/dalvikvm(6488): at maps.k.d.a((null):-1)
10-01 10:59:43.082: I/dalvikvm(6488): at maps.k.g.handleMessage((null):-1)
10-01 10:59:43.082: I/dalvikvm(6488): at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 10:59:43.082: I/dalvikvm(6488): at android.os.Looper.loop(Looper.java:130)
10-01 10:59:43.082: I/dalvikvm(6488): at maps.k.d.c((null):-1)
10-01 10:59:43.082: I/dalvikvm(6488): at maps.k.ag.c((null):-1)
10-01 10:59:43.082: I/dalvikvm(6488): at maps.ao.b.run((null):-1)
10-01 10:59:43.129: W/dalvikvm(6488): threadid=10: thread exiting with uncaught exception (group=0x40015560)
10-01 10:59:43.144: E/AndroidRuntime(6488): FATAL EXCEPTION: vts_com.jasonflaherty.snoteldata
10-01 10:59:43.144: E/AndroidRuntime(6488): java.lang.OutOfMemoryError
10-01 10:59:43.144: E/AndroidRuntime(6488): at maps.ao.d.a(Unknown Source)
10-01 10:59:43.144: E/AndroidRuntime(6488): at maps.i.cu.a(Unknown Source)
10-01 10:59:43.144: E/AndroidRuntime(6488): at maps.k.ah.a(Unknown Source)
10-01 10:59:43.144: E/AndroidRuntime(6488): at maps.k.d.a(Unknown Source)
10-01 10:59:43.144: E/AndroidRuntime(6488): at maps.k.g.handleMessage(Unknown Source)
10-01 10:59:43.144: E/AndroidRuntime(6488): at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 10:59:43.144: E/AndroidRuntime(6488): at android.os.Looper.loop(Looper.java:130)
10-01 10:59:43.144: E/AndroidRuntime(6488): at maps.k.d.c(Unknown Source)
10-01 10:59:43.144: E/AndroidRuntime(6488): at maps.k.ag.c(Unknown Source)
10-01 10:59:43.144: E/AndroidRuntime(6488): at maps.ao.b.run(Unknown Source)
10-01 10:59:43.394: D/dalvikvm(6488): GC_FOR_MALLOC freed 195K, 55% free 10116K/22151K, external 2433K/2688K, paused 153ms
10-01 10:59:43.433: W/ResourceType(6488): getEntry failing because entryIndex 939 is beyond type entryCount 1
10-01 10:59:43.433: W/ResourceType(6488): Failure getting entry for 0x7f0b03ab (t=10 e=939) in package 0 (error -2147483647)
10-01 10:59:43.433: E/GooglePlayServicesUtil(6488): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
10-01 10:59:43.769: D/dalvikvm(6488): GC_EXTERNAL_ALLOC freed 115K, 55% free 10102K/22151K, external 2433K/2688K, paused 121ms
10-01 10:59:43.824: E/dalvikvm-heap(6488): 80-byte external allocation too large for this process.
10-01 10:59:43.824: W/OSMemory(6488): External allocation of 80 bytes was rejected
10-01 10:59:43.925: D/dalvikvm(6488): GC_FOR_MALLOC freed <1K, 55% free 10102K/22151K, external 2433K/2688K, paused 101ms
10-01 10:59:44.019: W/dalvikvm(6488): threadid=17: thread exiting with uncaught exception (group=0x40015560)
10-01 10:59:44.027: I/Process(6488): Sending signal. PID: 6488 SIG: 9

最佳答案

How do I set this up and only add my markers per this method?

Google Maps Extension

map.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true));

方法正是这样做的。仅添加 Marker s 在 map 的可见区域。它之外的所有标记都由扩展库保存,但不会进行进程间通信以将它们放在 map 上。当用户滚动显示不同区域时,它们将被添加。

如果您认为 map 有问题,我会尝试的第一件事是使用默认标记图标或只创建一个 BitmapDescriptor对于所有 Marker小号:

BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.snotel_marker));
for (int i = 0; i < nsize; i++) {
// ...
m = map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(title)
.icon(icon);
// ...
}

这应该解决 OutOfMemoryError问题。


除此之外,您不想调用 setOnInfoWindowClickListener在一个循环中。一次就够了。
还有一件事:如果这就是您要保留的所有数据,您可以使用 MarkerOptions.snippetMarker.getSnippet为你的String desc .无需将其全部保留在 Map<Marker, MapMarkers> 中数据结构。如果您想在两个 String 旁边保留其他数据s 和 LatLng , 我建议使用 MarkerOptions.data(marks) (自 1.6 起)或 Marker.setData(marks)在扩展库中。稍后阅读 OnInfoWindowClickListener回调:

MapMarkers marks = (MapMarkers) marker.getData();

关于android - 仅加载我所在位置周围的标记 Google Map v2 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19120798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com