Skip to content

sbed/google-maps-services-java

 
 

Repository files navigation

Java Client for Google Maps Services

Build Status Maven Central Version Coverage Status

Use Java? Want to geocode something? Looking for directions? Maybe matrixes of directions? This library brings the Google Maps API Web Services to your Java application. Analytics

Usage

This example uses the Geocoding API.

GeoApiContext context = new GeoApiContext().setApiKey("AIza...");
GeocodingResult[] results =  GeocodingApi.geocode(context,
    "1600 Amphitheatre Parkway Mountain View, CA 94043").await();
System.out.println(results[0].formattedAddress);

For more usage examples, check out the tests.

Installation

Add the library to your project via Maven or Gradle.

Maven

<dependency>
    <groupId>com.google.maps</groupId>
    <artifactId>google-maps-services</artifactId>
    <version>(insert latest version)</version>
</dependency>

Gradle

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.google.maps:google-maps-services:(insert latest version)'
    ...
}

You can find the latest version at the top of this README or by searching Maven Central or Gradle, Please.

Note!

Keep in mind that the same terms and conditions apply to usage of the APIs when they're accessed through this library.

Features

Rate Limiting

Never sleep between requests again! By default requests are sent at a maximum of 10 queries per second to match the restrictions on the API. If you want to speed up or slow down requests, you can do that too, using new GeoApiContext(qps).

Retry on Failure

Automatically retry when intermittent failures occur. That is, when any of the retriable 5xx errors are returned from the API.

Keys and Client IDs

Business customers can use their client ID and secret to authenticate. Free customers can use their API key, too.

POJOs

Native objects for each of the API responses.

Asynchronous or synchronous -- you choose

All requests support synchronous or asynchronous calling style.

GeocodingApiRequest req = GeocodingApi.newRequest(context).address("Sydney");

// Synchronous
try {
    req.await();
    // Handle successful request.
} catch (Exception e) {
    // Handle error
}

req.awaitIgnoreError(); // No checked exception.

// Async
req.setCallback(new PendingResult.Callback<GeocodingResult[]>() {
  @Override
  public void onResult(GeocodingResult[] result) {
    // Handle successful request.
  }

  @Override
  public void onFailure(Throwable e) {
    // Handle error.
  }
});

API Coverage

The following APIs are supported:

Building the project

# Compile and package the project
./gradlew jar

# Run the tests. Note: you will need an API key to run the tests.
API_KEY=AIza.... ./gradlew test

# Run the tests with enterprise credentials.
CLIENT_ID=... CLIENT_SECRET=... ./gradlew test

# Generate documentation
./gradlew javadoc

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors