Skip to content

Instantly share code, notes, and snippets.

@rterp
Created July 29, 2016 22:56
Show Gist options
  • Save rterp/c2a7c9fb047f3c48082d992deaba46a4 to your computer and use it in GitHub Desktop.
Save rterp/c2a7c9fb047f3c48082d992deaba46a4 to your computer and use it in GitHub Desktop.
@FXML
public void addressTextFieldAction(ActionEvent event) {
geocodingService.geocode(address.get(), (GeocodingResult[] results, GeocoderStatus status) -> {
LatLong latLong = null;
if( status == GeocoderStatus.ZERO_RESULTS) {
Alert alert = new Alert(Alert.AlertType.ERROR, "No matching address found");
alert.show();
return;
} else if( results.length > 1 ) {
Alert alert = new Alert(Alert.AlertType.WARNING, "Multiple results found, showing the first one.");
alert.show();
latLong = new LatLong(results[0].getGeometry().getLocation().getLatitude(), results[0].getGeometry().getLocation().getLongitude());
} else {
latLong = new LatLong(results[0].getGeometry().getLocation().getLatitude(), results[0].getGeometry().getLocation().getLongitude());
}
map.setCenter(latLong);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment