谷歌地图Android API中的java.lang.OutOfMemoryError v2 [英] java.lang.OutOfMemoryError with google maps android api v2

查看:81
本文介绍了谷歌地图Android API中的java.lang.OutOfMemoryError v2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了这个程序来重叠圈子,以显示我一直在使用谷歌地图android api v2。大约2个小时后,我得到java.lang.OutOfMemoryError,堆大小大于分配。从堆栈跟踪...(堆大小= 98304KB,已分配= 86536KB)

为什么这占用了太多的内存来存储所有这些重叠的圆圈?

  public void onLocationChanged(Location location){

CircleOptions circleOptions = new CircleOptions()
.center(new LatLng(location.getLatitude(),location.getLongitude()));

circleOptions.radius(10); //以米为单位

mMap.addCircle(circleOptions);

}

有关如何减轻这种情况的建议?我想保留这些圈子,因此它不是使用map.clear()的选项。我还需要继续使用圆圈,因为它允许我在地图上设置路径宽度。

解决方案

位置管理器可以请参数:

 提供程序的名称,用于注册
minTime位置更新之间的最小时间间隔,以毫秒为单位
minDistance位置更新之间的最小距离(以米为单位)
监听器一个LocationListener,其每个位置将调用onLocationChanged(Location)方法update b
$ b locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER ,200,0,this);

增加位置更新之间的最短时间间隔或距离可以减少地图上的圆圈,从而增加程序在达到最大堆大小之前可以运行的时间。


I wrote this program to overlap circles to show where I've been using the google maps android api v2. After about 2 hours I get the java.lang.OutOfMemoryError with the heap size being larger than allocated. From stack trace... (Heap Size=98304KB, Allocated=86536KB)

Why does this take up so much memory to store all these overlapping circles?

public void onLocationChanged(Location location) {

     CircleOptions circleOptions = new CircleOptions()
        .center(new LatLng(location.getLatitude(), location.getLongitude()));

    circleOptions.radius(10); // In meters

          mMap.addCircle(circleOptions);

}

Any suggestions on how to mitigate this? I would like to keep the circles so it isn't an option to use map.clear(). Also I need to keep using the circles because it allows me to set a path width on the map.

解决方案

The location manager can take the parameters:

provider        the name of the provider with which to register
minTime         minimum time interval between location updates, in milliseconds
minDistance     minimum distance between location updates, in meters
listener        a LocationListener whose onLocationChanged(Location) method will be called for each location update

locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 200, 0, this);

Increasing the minimum time interval or distance between location updates will provide less circles on the map, thereby increasing the amount of time the program can be run before reaching the maximum heap size.

这篇关于谷歌地图Android API中的java.lang.OutOfMemoryError v2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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