Skip to content

OpenCageData/jopencage

Repository files navigation

JOpenCage

Maven Central Java workflow Javadoc

security status stability status

This package provides a Java client to the OpenCage Geocoding API: https://opencagedata.com/api

⚠️ This is an unstable branch that only contains SNAPSHOT versions; it is still under development. The latest stable version is 2.2.2 available on MavenCentral and this branch

Tutorial

You can find a comprehensive tutorial for using this package on the OpenCage site.

Getting started

Sign up for a free-trial API Key.

Usage

Maven

  <dependency>
    <groupId>com.opencagedata</groupId>
    <artifactId>jopencage</artifactId>
    <version>replace.with.version</version>
  </dependency>

Gradle

    implementation "com.opencagedata:jopencage:REPLACE.WITH.VERSION"

Examples

Forward

// In real live application the JOpenCageGeocoder should be a Singleton
JOpenCageGeocoder jOpenCageGeocoder = new JOpenCageGeocoder(YOUR_API_KEY);

JOpenCageForwardRequest request = new JOpenCageForwardRequest("Graz");
request.setMinConfidence(1);
request.setNoAnnotations(false);
request.setNoDedupe(true);
JOpenCageResponse response = jOpenCageGeocoder.forward(request); // try..catch or throw JOpenCageException

Reverse

// In real live application the JOpenCageGeocoder should be a Singleton
JOpenCageGeocoder jOpenCageGeocoder = new JOpenCageGeocoder(YOUR_API_KEY);

JOpenCageReverseRequest request = new JOpenCageReverseRequest(-22.6792, 14.5272);
request.setNoAnnotations(true);

JOpenCageResponse response = jOpenCageGeocoder.reverse(request);  // try..catch or throw JOpenCageException

Upgrading from 1.x or 2.x to 3.x

Starting with version 3.x, the methods forward() and reverse() can throw a com.opencagedata.jopencage.JOpenCageException.

Javadoc

https://opencagedata.github.io/jopencage/javadoc/

Libraries

  • JDK 17+
  • Apache Http Client
  • FasterXml Jackson
  • Slf4j

Testing

For running the tests you have to use your OWN OpenCage Geocoding API Key. Get a free trial key at https://opencagedata.com

./gradlew -DOPENCAGE_API_KEY=<your apikey> test

Gradle

./gradlew wrapper --gradle-version 9.2.1

Contribute

See Contribution Guidelines.

Changelog

See CHANGELOG.

License

Apache 2.0. Please see LICENSE.

History

Until July 2023 this library was maintained by Michael Oberwasserlechner. At his request due to lack of time to work on it the libary was then taken over by OpenCage GmbH. Thanks, Michael!

Who is OpenCage GmbH?

OpenCage Logo

We run the OpenCage Geocoding API. Learn more about us.

We also run Geomob, a series of regular meetups for location based service creators, where we do our best to highlight geoinnovation. If you like geo stuff, you will probably enjoy the Geomob podcast.

About

OpenCage geocoding client for Java

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 11

Languages