Documentation‎ > ‎

JxMaps JavaFX Quick Start Guide

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

1. Get your own Google Maps API key

You can do it here: https://developers.google.com/maps/documentation/javascript/get-api-keyThe API key is used to track API requests associated with your project for usage and billing.

Google Maps is no longer free. You have to associate a credit card so that you can get billed if your site has requests that exceed the $200 credit they give you monthly for free, otherwise you will get the watermarked maps. For more information, see: https://cloud.google.com/maps-platform/pricing/

2. Download Library

To download JxMaps library navigate to https://www.teamdev.com/jxmaps and click the 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

3. 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

4. Create a Java project

Create a new Java Project using your favorite IDE.

5. Add JxMaps libraries to the project

Add JxMaps libraries and evaluation licence 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

6. Create Hello, World! application

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

package com.teamdev.jxmaps.examples;

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

import com.teamdev.jxmaps.GeocoderCallback;
import com.teamdev.jxmaps.GeocoderRequest;
import com.teamdev.jxmaps.GeocoderResult;
import com.teamdev.jxmaps.GeocoderStatus;
import com.teamdev.jxmaps.InfoWindow;
import com.teamdev.jxmaps.Map;
import com.teamdev.jxmaps.MapReadyHandler;
import com.teamdev.jxmaps.MapStatus;
import com.teamdev.jxmaps.Marker;
import com.teamdev.jxmaps.javafx.MapView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;


public class HelloWorld extends Application {
@Override
public void init() throws Exception {
MapView.
InitJavaFX();
}

@Override
public void start(final Stage primaryStage) {         MapViewOptions options = new MapViewOptions();        options.importPlaces();        options.setApiKey("<your_google_maps_api_key>");
        final MapView mapView = new MapView(options);

mapView.setOnMapReadyHandler(
new MapReadyHandler() {
@Override
public void onMapReady(MapStatus status) {
if (status == MapStatus.MAP_STATUS_OK) {
final Map map = mapView.getMap();
map.setZoom(
5.0);
GeocoderRequest request =
new GeocoderRequest();
request.setAddress(
"Kharkiv, UA");

mapView.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);
}
}
});
}
}
});

Scene scene =
new Scene(new BorderPane(mapView), 700, 500);
primaryStage.setTitle(
"JxMaps - Hello, World!");
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}

7. Run the Program

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