【问题标题】:Adding x number Markers to Codenameone MapContainer at runtime在运行时向 Codenameone MapContainer 添加 x 个标记
【发布时间】:2018-12-28 12:33:15
【问题描述】:

我已检索到大量 latlong 值并存储在 ArrayList 中。我想使用 ArrayList 中的 latlong 值向我的 MapContainer 添加标记。然而,挑战在于引脚永远不会在地图上正确定位(模拟器和设备)。我已经尝试了一切,但仍然没有成功。这是一个工作示例。这可行,但引脚在运行时定位错误。

    Form hi = new Form("cReporter", new BorderLayout());
        hi.setScrollableY(false);
        Container n = new Container(new BorderLayout());
        MapContainer mc = new MapContainer();//
        mc.setShowMyLocation(true);
        hi.add("Center", mc);
        List lx = new ArrayList();
        addPoints(lx);
        hi.show();
        addMarkers(mc, lx);

       public void addPoints(List lx)
       {
           Map m= new HashMap();
           m.put("long", 8.993082);
           m.put("lat", 38.747393);
           lx.add(m);

           m= new HashMap();
           m.put("long", 8.988419);
           m.put("lat", 38.727094);
           lx.add(m);

           m= new HashMap();
           m.put("long", 8.991724);
           m.put("lat", 38.775203);
           lx.add(m);
       }

       public void addMarkers(MapContainer mc, List coordList)
   {    

        Style s = new Style();
        s.setFgColor(0xff0000);
        s.setBgTransparency(0);
        FontImage markerImg = FontImage.createMaterial(FontImage.MATERIAL_PLACE, s, 5);

       for(Object m: coordList)
       {
           Map p= (Map)m;
           Coord moscone = new Coord(Double.parseDouble(p.get("lat").toString()), Double.parseDouble(p.get("long").toString()));
           mc.addMarker(EncodedImage.createFromImage(markerImg, false), mc.getCameraPosition(), "Hi marker", "Optional long description", new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    System.out.println("Bounding box is "+mc.getBoundingBox());
                    ToastBar.showMessage("You clicked the marker", FontImage.MATERIAL_PLACE);
                }
            });
           mc.setCameraPosition(moscone);
           mc.revalidate();
       }

   }

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    我猜您没有为地图使用正确的投影纬度/经度值,因为这些值因不同的实现而异。有关不同类型定位的讨论,请参阅此:Source event strange latitude & longitude

    我注意到您为每个标记位置创建了一个新的编码图像。这是非常低效的,因为每个这样的图像都会占用 RAM,并且执行 x100 可能会带来严重的开销。这是您应该重复使用的图像。

    【讨论】:

    • 感谢 Shai...我混淆了纬度/经度值...感谢您指出 EncodedImage 问题
    猜你喜欢
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 2017-03-01
    • 2020-10-06
    相关资源
    最近更新 更多