【问题标题】:How to add multiple marks on MapView - over a hundred如何在 MapView 上添加多个标记 - 超过一百
【发布时间】:2011-01-13 23:24:59
【问题描述】:

我按照开发者网站上的 Hello MapView 教程进行操作,一切正常。但现在我需要扩展它以添加大约 150 个标记,而我当前的方法会使我的应用程序崩溃。

原因:keyDispatchingTimedOut

我的设置如下..

包含地图数据的四个字符串数组,都具有(并且总是)具有完全相同数量的索引,并且 fId[0] == fLatitude[0] == fLongitude[0] == fDetails[0] ,等等:

    String[] fId;
    String[] fLatitude;
    String[] fLongitude;
    String[] fDetails;

到目前为止,这就是我在地图上绘制点的方式。这显然不是正确的方法,因为地图不断崩溃:

        List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
    FriendItemizedOverlay itemizedoverlay = new FriendItemizedOverlay(drawable, mapView.getContext());

    for(int i=0;i<aLatitude.length;i++){

        Double intLon = Double.parseDouble(aLongitude[i]);
        Double intLat = Double.parseDouble(aLatitude[i]);

        GeoPoint point = new GeoPoint((int)(intLat * 1E6), 
                (int)(intLon * 1E6));
        OverlayItem overlayitem = new OverlayItem(point, "Friend ", "Something");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);

    }

如果您需要更多信息,请在 cmets 中告诉我,谢谢。

Logcat:

01-13 18:39:34.732: 错误/MapActivity(1085): 无法获取连接工厂客户端 01-13 18:40:14.473: ERROR/ActivityManager(69): ANR in com.example.friendapp (com.example.friendapp/.FriendMaps) 01-13 18:40:14.473: 错误/ActivityManager(69): 原因: keyDispatchingTimedOut 01-13 18:40:14.473:错误/活动管理器(69):负载:2.39 / 0.78 / 0.42 01-13 18:40:14.473: ERROR/ActivityManager(69): CPU 使用率从 6026ms 到 0ms 前: 01-13 18:40:14.473: 错误/ActivityManager(69): 93% 1085/com.example.friendapp: 93% 用户 + 0% 内核/错误: 25 次要 01-13 18:40:14.473: 错误/ActivityManager(69): 2.6% 69/system_server: 1.8% 用户 + 0.8% 内核/故障: 3 次小 01-13 18:40:14.473: 错误/ActivityManager(69): 1.1% 875/com.google.process.gapps: 0% 用户 + 1.1% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 1.1% 980/com.android.quicksearchbox: 0% 用户 + 1.1% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 0.9% 133/com.android.launcher: 0% 用户 + 0.9% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 0.1% 40/adbd: 0% 用户 + 0.1% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 100% 总计: 95% 用户 + 4.1% 内核 01-13 18:40:14.473: ERROR/ActivityManager(69): CPU 使用率从 2192ms 到 2863ms 后: 01-13 18:40:14.473: 错误/ActivityManager(69): 80% 1085/com.example.friendapp: 80% 用户 + 0% 内核/故障: 3 次小 01-13 18:40:14.473: 错误/ActivityManager(69): 77% 1085/bile.friendapp: 77% 用户 + 0% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 16% 69/system_server: 4.8% 用户 + 11% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 14% 101/InputDispatcher: 3.2% 用户 + 11% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 1.6% 70/HeapWorker: 1.6% 用户 + 0% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 0.5% 133/com.android.launcher: 0% 用户 + 0.5% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 0.5% 134/HeapWorker: 0% 用户 + 0.5% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 0.6% 980/com.android.quicksearchbox: 0% 用户 + 0.6% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 1.3% 981/HeapWorker: 0% 用户 + 1.3% 内核 01-13 18:40:14.473: 错误/ActivityManager(69): 100% 总计: 80% 用户 + 19% 内核 01-13 18:40:20.702: ERROR/InputDispatcher(69): channel '406f88b8 com.example.friendapp/com.example.friendapp.FriendMaps (server)' ~ 消费者关闭输入通道或发生错误。事件=0x8 01-13 18:40:20.712: ERROR/InputDispatcher(69): channel '406f88b8 com.example.friendapp/com.example.friendapp.FriendMaps (server)' ~ Channel 已不可恢复地损坏,将被丢弃!

【问题讨论】:

  • 它是如何崩溃的。你的 logcat 怎么说。
  • @Falmarri - 标签 - ActivityManager - com.example.friends 中的 ANR,然后原因:keyDispatchingTimedOut...
  • 显示更多你的 logcat。编辑您的问题并包含所有相关的堆栈跟踪。
  • @Falmarri - 刚刚习惯了 logcat - 这就是错误视图的所有输出。你还需要什么吗?
  • 重新考虑您的地图标记管理,一个月前我遇到了同样的问题。 stackoverflow.com/questions/3529022/…我使用markermanager将标记与资源(图像)链接起来,它对我有用

标签: java android arrays android-mapview


【解决方案1】:

您在地图上添加了 150 次相同的叠加层。请只添加一次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 2021-07-22
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多