Skip to content

Instantly share code, notes, and snippets.

@alfredoem
Created November 18, 2019 15:24
Show Gist options
  • Save alfredoem/823c070c7326b9041a896357a0f98a74 to your computer and use it in GitHub Desktop.
Save alfredoem/823c070c7326b9041a896357a0f98a74 to your computer and use it in GitHub Desktop.
Google Maps Platform test
package com.example;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.maps.GeoApiContext;
import com.google.maps.GeocodingApi;
import com.google.maps.errors.ApiException;
import com.google.maps.model.GeocodingResult;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class GoogleMapsService {
public static void main(String[] args) throws InterruptedException, IOException, ApiException {
GeoApiContext context = new GeoApiContext.Builder().apiKey("API_KEY")
.connectTimeout(30L, TimeUnit.SECONDS).readTimeout(30L, TimeUnit.SECONDS).build();
GeocodingResult[] results = GeocodingApi.geocode(context,
"1600 Amphitheatre Parkway Mountain View, CA 94043").await();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
System.out.println(gson.toJson(results[0].addressComponents));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment