Documentation‎ > ‎

JxMaps in Eclipse

1. Run Eclipse and create a new Java Project: 

JxMaps in Eclipse - 1

2. Enter Project name and click Finish button: 

JxMaps in Eclipse - 2

3. Open Project Properties dialog: 

JxMaps in Eclipse - 3

4. Click Add External JARs... button to add JxMaps JAR files to the project, then click OK button: 

JxMaps in Eclipse - 4

5. Create a new HelloWorld class and click Finish button:  

JxMaps in Eclipse - 5

JxMaps in Eclipse - 6

6. Insert the code of the HelloWorld: 

JxMaps in Eclipse - 7

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();         options.setApiKey("<your_google_maps_api_key>");
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);
}
}
7. Run HelloWorld:
JxMaps in Eclipse - 8

8. You'll see a Java window with embedded Map component where sample map is loaded: 

JxMaps in Eclipse - 9