CN1 MapLayout组件未显示为固定状态

时间:2018-12-07 09:31:14

标签: google-maps layout codenameone

如标题所述。我添加到MapLayout的标签(“顶部”和“底部”)并没有真正固定到给定的坐标。我是否想避免这种现象(请参见下面的屏幕记录)?

enter image description here

我的示例代码:

    final MapContainer mapContainer = new MapContainer(API_KEY, false);


    Container actual = new Container();
    actual.setLayout(new MapLayout(mapContainer, actual));

    Form f = new Form("Maps", new LayeredLayout());

    f.add(mapContainer);
    f.add(actual);

    String[] coordinates = new String[] {
        "50.963642, 7.121855"  
    };

    List<MapContainer.MapObject> addedMarkers = new ArrayList<>();
    List<Coord> coords = new ArrayList<>();

    EncodedImage ei = EncodedImage.createFromImage(
            FontImage.createMaterial(FontImage.MATERIAL_GPS_FIXED, f.getUnselectedStyle())
            , false);

    for(String cStr : coordinates) {
        Coord c = toCoordinate(cStr);
        MapContainer.MapObject obj = mapContainer.addMarker(ei, c, "Marker", "Long text", (evt) -> {

            log.p("clicked on marker" + c);

            Component cmp1 = new Label("top");
            actual.addComponent(c, cmp1);
            MapLayout.setHorizontalAlignment(cmp1, 0.5f);
            MapLayout.setVerticalAlignment(cmp1, 1f);

            Component cmp2 = new Label("bottom");
            actual.addComponent(c, cmp2);
            MapLayout.setHorizontalAlignment(cmp2, 0.5f);
            MapLayout.setVerticalAlignment(cmp2, 0f);
        });

        coords.add(c);
        addedMarkers.add(obj);
    }


    f.revalidate();

    f.show();

1 个答案:

答案 0 :(得分:0)

尝试使用此新API https://www.codenameone.com/blog/map-component-positioning-revisited.html

它比以前的地图布局方法更好,因为它可以将组件来回转换为标记。