Created
November 18, 2019 15:24
-
-
Save alfredoem/823c070c7326b9041a896357a0f98a74 to your computer and use it in GitHub Desktop.
Google Maps Platform test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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