-
-
Save afrigis/fb9a4d5f2f5cce0063fab3b91a26bdb3 to your computer and use it in GitHub Desktop.
libraries_java_sample
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.afrigis.services.sample; | |
import java.util.List; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.Future; | |
import com.afrigis.services.AfriGISServices; | |
import com.afrigis.services.ServiceCallFactory; | |
import com.afrigis.services.geocode.AddressRequest; | |
import com.afrigis.services.geocode.AddressResponse; | |
import com.afrigis.services.geocode.GeocodeGroupOption; | |
import com.afrigis.services.geocode.LocationResult; | |
public class Main { | |
public static void main(String[] args) throws InterruptedException, ExecutionException { | |
String key = "<YOUR KEY>"; | |
String secret = "<YOUR SECRET>"; | |
// Construct the services factory - keep this instance around! | |
ServiceCallFactory factory = AfriGISServices.instance(key, secret); | |
// Create a Geocode Address request with your searchText | |
AddressRequest request = new AddressRequest("Hatfield, Pretoria"); | |
// Adding a group will enforce the service to add grouping to the result | |
// array | |
request.addGroup(GeocodeGroupOption.geometry); | |
// Make a blocking asynchronous request to get a typed response | |
Future<AddressResponse> resultsFuture = factory.getAsync(request); | |
AddressResponse result = resultsFuture.get(); | |
// Display formatted address, latitude and longitude of the result array | |
for (LocationResult address : result.listResults()) { | |
System.out.printf("Formatted Address:\t%s\n", address.getFormattedAddress()); | |
System.out.printf("Latitude:\t\t%2.6f\n", address.getGeometry().getLocation().getLatitude()); | |
System.out.printf("Longitude:\t\t%2.6f\n\n", address.getGeometry().getLocation().getLongitude()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment