Documentation‎ > ‎

JxMaps in IntelliJ IDEA

1. Run IntelliJ IDEA and create a new empty Java Project: 



2. Enter Project name and click Finish button.


3. Create a new Java Module: 





4. Add libraries to the Java Module dependencies list: 


 


5. Configure Project JDK (if necessary): 


6. Create HelloWorld class: 


 

7. Insert source code of the HelloWorld example:

HelloWorld source code:

import com.teamdev.jxmaps.*;
import com.teamdev.jxmaps.swing.MapView;

import javax.swing.*;
import java.awt.*;

public class HelloWorld extends MapView {
public HelloWorld(MapViewOptions options) {
super(options);
setOnMapReadyHandler(new MapReadyHandler() {
@Override
public void onMapReady(MapStatus status) {
if (status == MapStatus.MAP_STATUS_OK) {
final Map map = getMap();
map.setZoom(5.0);
GeocoderRequest request = new GeocoderRequest(map);
request.setAddress("Kharkiv, UA");

getServices().getGeocoder().geocode(request, new GeocoderCallback(map) {
@Override
public void onComplete(GeocoderResult[] result, GeocoderStatus status) {
if (status == GeocoderStatus.OK) {
map.setCenter(result[0].getGeometry().getLocation());
Marker marker = new Marker(map);
marker.setPosition(result[0].getGeometry().getLocation());

final InfoWindow window = new InfoWindow(map);
window.setContent("Hello, World!");
window.open(map, marker);
}
}
});
}
}
});
}

public static void main(String[] args) {

MapViewOptions options = new MapViewOptions();
options.importPlaces();
final HelloWorld mapView = new HelloWorld(options);

JFrame frame = new JFrame("JxMaps - Hello, World!");

frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(mapView, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
8. Run HelloWorld program: