Documentation‎ > ‎

JxMaps Swing Quick Start Guide

In this Quick Start Guide you will learn how to get started with JxMaps library.

1. Download Library

To download JxMaps library navigate to https://www.teamdev.com/jxmaps and click Download button. Unzip the downloaded archive into a directory on your computer (e.g. D:\Projects\MyProject). When you unzip the archive it will give you directory structure inside D:\Projects\MyProject\ as follows:

lib\
    jxmaps.jar          // JxMaps library
    jxmaps-win.jar      // JxMaps binaries for Windows
    jxmaps-mac.jar      // JxMaps binaries for macOS
    jxmaps-linux32.jar   // JxMaps binaries for Linux 32-bit
    jxmaps-linux64.jar   // JxMaps binaries for Linux 64-bit
samples\                // API samples
doc\javadoc\            // Public API Javadocs
doc\guide\              // Programmer's and Quick Start Guide
demo\                   // Demo application
Readme.txt              // Readme file
License agreement.txt   // License agreement

2. Getting Evaluation Licence

To get free JxMaps 30-days evaluation licence please fill the web form and click Get Evaluation button. You will receive an email with a link that you can use to download evaluation license file — license.jar. Download the license.jar file and save it in the D:\Projects\MyProject\lib\ directory.

lib\
    jxmaps.jar          // JxMaps library
    jxmaps-win.jar      // JxMaps binaries for Windows
    jxmaps-mac.jar      // JxMaps binaries for macOS
    jxmaps-linux32.jar   // JxMaps binaries for Linux 32-bit
    jxmaps-linux64.jar   // JxMaps binaries for Linux 64-bit
    license.jar

3. Create a Java project

Create a new Java Project using your favorite IDE.

4. Add JxMaps libraries to the project

Add JxMaps libraries and evaluation license to the Project in the IDE:

D:\Projects\MyProject\lib\jxmaps.jar
D:\Projects\MyProject\lib\jxmaps-win.jar
D:\Projects\MyProject\lib\jxmaps-mac.jar
D:\Projects\MyProject\lib\jxmaps-linux32.jar
D:\Projects\MyProject\lib\jxmaps-linux64.jar
D:\Projects\MyProject\lib\license.jar

5. Create Hello, World! application

In your Java Project create a new HelloWorld Java class with the following content:

/*
* Copyright (c) 2000-2017 TeamDev Ltd. All rights reserved.
* TeamDev PROPRIETARY and CONFIDENTIAL.
* Use is subject to license terms.
*/

package com.teamdev.jxmaps.examples;

import com.teamdev.jxmaps.GeocoderRequest;
import com.teamdev.jxmaps.GeocoderCallback;
import com.teamdev.jxmaps.Marker;
import com.teamdev.jxmaps.MapViewOptions;
import com.teamdev.jxmaps.InfoWindow;
import com.teamdev.jxmaps.GeocoderStatus;
import com.teamdev.jxmaps.GeocoderResult;
import com.teamdev.jxmaps.Map;
import com.teamdev.jxmaps.MapReadyHandler;
import com.teamdev.jxmaps.MapStatus;
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);
}
}

6. Run the Program

Compile and run HelloWorld program. You will see the following window: