public class FrmMap extends com.codename1.ui.Form {
protected MapContainer cnt = new MapContainer(new GoogleMapsProvider("AIzaSyDq8k10JtB2aViAR30rKK-o2zfCAgTQg-0"));
Container cntMain = new Container(new BorderLayout());
protected Label lblStatus = new Label("Status");
public FrmMap() {
this(Resources.getGlobalResources());
}
public FrmMap(Resources resourceObjectInstance) {
initManualComponents();
Display.getInstance().callSerially(() -> {
centerMapToLocation();
});
}
protected void initManualComponents() {
setLayout(new BorderLayout());
setTitle("Map");
setName("FrmMap");
this.setScrollable(false);
cnt.addMapListener(new MapListener() {
@Override
public void mapPositionUpdated(Component source, int zoom, Coord center) {
onMapUpdate(zoom, center);
}
});
cntMain.add(BorderLayout.CENTER, cnt);
cntMain.add(BorderLayout.SOUTH, lblStatus);
this.add(BorderLayout.CENTER, cntMain);
}
protected void centerMapToLocation() {
LocationManager l = LocationManager.getLocationManager();
l.setLocationListener(new LocationListener() {
public void locationUpdated(Location loc) {
Coord c = new Coord(loc.getLatitude(), loc.getLongitude());
cnt.zoom(c , 13);
l.setLocationListener(null);
onMapUpdate(13, c);
}
public void providerStateChanged(int newState) {
}
});
}
protected void onMapUpdate(int zoom, Coord center) {
cnt.clearMapLayers();
cnt.addMarker(null,
center,
"Test", "Test",
new ActionListener<ActionEvent>() {
public void actionPerformed(ActionEvent evt) {
onClickList();
}
}
);
lblStatus.setText("");
}
protected void onClickList() {
Log.p("Clicked");
}
}