Once you have the auth object, you'll then need to create an OkHi user object.
// firstName, lastName, phoneNumber// only phoneNumber is requiredOkHiUser user =newOkHiUser("Bob","Markson","0721856492");
To enable the LocationManager to match your company branding, create an OkHi style object.
// hexColor, Company Name, LogoOkHiStyle style = new OkHiStyle("#ba0c2f", "Jubilee Insurance", "https://jubileeinsurance.com/ke/wp-content/themes/_ji/images/logo.svg");
Once you have all that you can finally create an OkHi object that will enable you to launch the Location Manager
// refer to notes below OkHi okhi = new OkHi(auth, user, style, OkHiLaunchMode.SELECT_LOCATION, OkHiDevMode.SANDBOX, new OkHiLocationHandler() {
@OverridepublicvoidonSuccess(OkHiLocation location,OkHiUser user) {// TODO: handle success hereSystem.out.println(location.title); } @OverridepublicvoidonError(OkHiError error) {// TODO: handle error hereSystem.out.println(error.code);System.out.println(error.message); } @OverridepublicvoidonCloseRequest() {// TODO: handle case when user taps the close buttonSystem.out.println("close me"); }});
Notes 📝
OkHiLaunchMode.SELECT_LOCATION enables the Location Manager to fetch a list of pre-existing addresses. A different mode available is OkHiLaunchMode.START_APP which defaults the Location Manager to its normal address creation flow.
OkHiDevMode.SANDBOX allows you to work in sandbox mode. Change this to OkHiDevMode.PRODUCTION once you're ready to go live!
The OkHiLocationHandler enables you to listen for success, error and close events Once a location has been created or selected the onSuccess method will be called. If an error does occur e.g no internet connection, the onError method will be called. Be sure to inspect the code and message properties when this happens.
When a user taps the close button in the Location Manager the onCloseRequest method will be called. At this point you can remove the Location Manager from view.
The OkHiLocation object has the following properties:
packagesample;importjavafx.application.Application;importjavafx.geometry.Insets;importjavafx.scene.Parent;importjavafx.scene.Scene;importjavafx.scene.control.Button;importjavafx.scene.layout.HBox;importjavafx.stage.Stage;importokhi.*;publicclassMainextendsApplication {privateStage stage; @Overridepublicvoidstart(Stage stage) throwsException{this.stage= stage;Button button =newButton("Create OkHi Location");button.setOnAction(actionEvent -> {this.launchOkHiLocationManager(); });HBox hbox =newHBox(button);hbox.setPadding(newInsets(10,5,10,5));this.changeScene(hbox); }publicvoidlaunchOkHiLocationManager() {OkHiAuth auth =newOkHiAuth("r:b59a93ba7d80a95d89dff8e4c52e259a");OkHiUser user =newOkHiUser("Bob","Markson","0721856492"); OkHiStyle style = new OkHiStyle("#ba0c2f", "Jubilee Insurance", "https://jubileeinsurance.com/ke/wp-content/themes/_ji/images/logo.svg");
OkHi okhi = new OkHi(auth, user, style, OkHiLaunchMode.SELECT_LOCATION, OkHiDevMode.SANDBOX, new OkHiLocationHandler() {
@OverridepublicvoidonSuccess(OkHiLocation location,OkHiUser user) {// TODO: handle success hereSystem.out.println(location.title); } @OverridepublicvoidonError(OkHiError error) {// TODO: handle error hereSystem.out.println(error.code); } @OverridepublicvoidonCloseRequest() {// TODO: handle case when user taps the close buttonSystem.out.println("close me"); } });Parent locationManager =okhi.locationManager();changeScene(locationManager); }publicvoidchangeScene(Parent sceneType) {Scene scene =newScene(sceneType,960,600);stage.setTitle("OkHi LocationManager Demo");stage.setScene(scene);stage.show(); }publicstaticvoidmain(String[] args) {launch(args); }}
Next steps
Backend Integration: Address Interactions
Integrate the Address Interactions API to start collecting your users' interactions with their address to enable you to get rich insights to make more informed business decisions using the insights data.
We appreciate any feedback you have for us. Let us know if something is not working. If you have a fix for it, great! Here's a link to the GitHub repo, looking forward to your pull requests.