【发布时间】: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