How to add MapView in JPanel of JDialog along with another JPanel

145 Views Asked by At

I want extract GPS coordinates using #jxmaps. For that purpose i have added two JPanel. One panel to hold few buttons and text Fields and in other Panel i want to add MapView. I have tried this

    JPanel mypanel = new JPanel();//null;
    JPanel mypanel2 = new JPanel();
    mypanel.setLayout(new BorderLayout(200,100));
    mypanel.setVisible(true);
    mypanel.add(mapView, BorderLayout.CENTER);   
    JFrame frame = new JFrame("JxMaps - Hello, World!");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.add(mypanel, BorderLayout.CENTER);
   frame.add(mypanel2, BorderLayout.EAST);
    frame.setSize(700, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true); 

But its not working. Can anyone please guide me how to do that?

Regards Aamir

1

There are 1 best solutions below

0
On

Unfortunately, provided part of source code doesn't have information about mapView initialization.

I tried to run your sample and it is working correctly on my side. I initialized mapView in the following way:

MapView mapView = new MapView();
mapView.setOnMapReadyHandler(new MapReadyHandler() {
   @Override
   public void onMapReady(MapStatus status) {
      Map map = mapView.getMap();
      map.setCenter(new LatLng(35.91466, 10.312499));
      map.setZoom(2.0);
   }
});

Could you explain more detailed what error do you have?