OkHi on your website

Display and access user's OkHi locations on your website.

The OkHi JavaScript library provides you with a quick and easy way to start collecting high accuracy location information from your users. Its extremely light-weight (~5kb), which eliminates any load performance concerns.

Video demo

New user checkout, delivery address collection

Return user checkout, zero click pre-selected delivery address

Prerequisites

  • api-key: You can obtain an api key by signing up here

Onward to the code 🚀

Include the OkHi JavaScript library to your HTML document. Make sure to place the script tag above your own JavaScript file.

Script tag
<script src="https://cdn.okhi.io/sandbox/web/v4/okhi.min.js">
HTML Document
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>My site name</title>
</head>
<body>
  <script src="https://cdn.okhi.io/sandbox/web/v4/okhi.min.js"></script>
  <script src="my_custom_javascript.js"></script>
</body>
</html>

Displaying a user's OkHi Location Card

The OkHi Location Card displays the most recently used location by the user. It also allows them to create or select another location via the Location Manager. To get started, create a div on your HTML Document where you'd want to display the location card and use the OkHi library as shown below. In the example the user's phone number is obtained from the data attribute in the HTML document, but feel free to customise this to however that suits you.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>My site name</title>
</head>
<body>
  <div 
    id="lets-okhi" 
    data-firstname="John" 
    data-lastname="Doe" 
    data-phone="0722xxxxxx">
  </div>
  <script src="https://cdn.okhi.io/sandbox/web/v4/okhi.min.js"></script>
  <script src="my_custom_javascript.js"></script>
</body>
</html>

*IMPORTANT* The onSuccess callback may be called multiple times as the user changes or manages their location.

Launching the OkHi Location Manager

The OkHi Location Manager enables the user to create or select an already existing location. It can be launched from a simple button click or any other triggers you wish to have. In the example below the user information is obtained from the data attribute in the HTML document, but feel free to customise this to however that suits you.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>My site name</title>
</head>
<body>
  <button 
    id="lets-okhi" 
    data-firstname="John" 
    data-lastname="Doe" 
    data-phone="0722xxxxxx">
    Select your location
  </button>
  <script src="https://cdn.okhi.io/sandbox/web/v4/okhi.min.js"></script>
  <script src="my_custom_javascript.js"></script>
</body>
</html>

Want more customization options? We've got you covered! Check out the API Reference for styling configuration and more

Last updated