Skip to content

Instantly share code, notes, and snippets.

@afrigis
Last active April 8, 2016 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afrigis/fb9a4d5f2f5cce0063fab3b91a26bdb3 to your computer and use it in GitHub Desktop.
Save afrigis/fb9a4d5f2f5cce0063fab3b91a26bdb3 to your computer and use it in GitHub Desktop.
libraries_java_sample
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