如何在MapView上添加多个标记——一百多个

发布于 2024-10-12 09:06:33 字数 3466 浏览 6 评论 0原文

我按照开发者网站上的 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);

    }

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

日志猫:

01-13 18:39:34.732: 错误/MapActivity(1085): 无法获取连接工厂客户端 01-13 18:40:14.473: 错误/ActivityManager(69): com.example.friendapp 中的 ANR (com.example.friendapp/.FriendMaps) 01-13 18:40:14.473:错误/ActivityManager(69):原因:keyDispatchingTimedOut 01-13 18:40:14.473:错误/ActivityManager(69):负载:2.39 / 0.78 / 0.42 01-13 18:40:14.473:错误/ActivityManager(69):CPU 使用率从 6026 毫秒到 0 毫秒前: 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:错误/ActivityManager(69):CPU 使用率从 2192 毫秒到 2863 毫秒之后: 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): 通道 '406f88b8 com.example.friendapp/com.example.friendapp.FriendMaps (server)' ~ 消费者关闭了输入通道或发生错误。事件=0x8 01-13 18:40:20.712: ERROR/InputDispatcher(69): 通道 '406f88b8 com.example.friendapp/com.example.friendapp.FriendMaps (server)' ~ 通道已不可恢复地损坏,将被处置!

I followed the Hello MapView tutorial on the developer site, and got everything working well. But now I need to expand upon that to add around 150 markers, and my current method crashes my app.

Reason: keyDispatchingTimedOut

My set up is as follows..

Four String arrays with the data for the map, all have (and always will) have the exact same number of indexes and fId[0] == fLatitude[0] == fLongitude[0] == fDetails[0], and so on:

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

As of now this is how I am plotting the points on the map. This is obviously not the correct way because the map keeps crashing:

        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);

    }

Let me know in the comments if you need anymore info, thanks.

Logcat:

01-13 18:39:34.732: ERROR/MapActivity(1085): Couldn't get connection factory client
01-13 18:40:14.473: ERROR/ActivityManager(69): ANR in com.example.friendapp (com.example.friendapp/.FriendMaps)
01-13 18:40:14.473: ERROR/ActivityManager(69): Reason: keyDispatchingTimedOut
01-13 18:40:14.473: ERROR/ActivityManager(69): Load: 2.39 / 0.78 / 0.42
01-13 18:40:14.473: ERROR/ActivityManager(69): CPU usage from 6026ms to 0ms ago:
01-13 18:40:14.473: ERROR/ActivityManager(69): 93% 1085/com.example.friendapp: 93% user + 0% kernel / faults: 25 minor
01-13 18:40:14.473: ERROR/ActivityManager(69): 2.6% 69/system_server: 1.8% user + 0.8% kernel / faults: 3 minor
01-13 18:40:14.473: ERROR/ActivityManager(69): 1.1% 875/com.google.process.gapps: 0% user + 1.1% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 1.1% 980/com.android.quicksearchbox: 0% user + 1.1% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 0.9% 133/com.android.launcher: 0% user + 0.9% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 0.1% 40/adbd: 0% user + 0.1% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 100% TOTAL: 95% user + 4.1% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): CPU usage from 2192ms to 2863ms later:
01-13 18:40:14.473: ERROR/ActivityManager(69): 80% 1085/com.example.friendapp: 80% user + 0% kernel / faults: 3 minor
01-13 18:40:14.473: ERROR/ActivityManager(69): 77% 1085/bile.friendapp: 77% user + 0% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 16% 69/system_server: 4.8% user + 11% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 14% 101/InputDispatcher: 3.2% user + 11% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 1.6% 70/HeapWorker: 1.6% user + 0% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 0.5% 133/com.android.launcher: 0% user + 0.5% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 0.5% 134/HeapWorker: 0% user + 0.5% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 0.6% 980/com.android.quicksearchbox: 0% user + 0.6% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 1.3% 981/HeapWorker: 0% user + 1.3% kernel
01-13 18:40:14.473: ERROR/ActivityManager(69): 100% TOTAL: 80% user + 19% kernel
01-13 18:40:20.702: ERROR/InputDispatcher(69): channel '406f88b8 com.example.friendapp/com.example.friendapp.FriendMaps (server)' ~ Consumer closed input channel or an error occurred. events=0x8
01-13 18:40:20.712: ERROR/InputDispatcher(69): channel '406f88b8 com.example.friendapp/com.example.friendapp.FriendMaps (server)' ~ Channel is unrecoverably broken and will be disposed!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如梦亦如幻 2024-10-19 09:06:33

您将相同的叠加层添加到地图 150 次。请仅添加一次。

You are adding the same overlay 150 times to the map. Please only add it once.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文