Location Permission

Helps customers to enable location services on the device.

Description

The requestLocationPermission() action triggers the native permission prompt on the user's device, allowing your app to request access to GPS and network-based location data.

This action is used to provide location-aware features, such as finding the nearest physical store or calculating shipping distances. When invoked, the device will display the OS-native permission page (iOS/Android), usually offering options like "Allow While Using App" or "Allow Once."

Function Description

VajroSDK.actions.requestLocationPermission()

Structure of Response

StatusResponse
Success{ "status": "success", "message": "Action executed" }
Failed{ "status": "failed", "message": "Action not executed " }
Unexpected Error{ "status": "error", "errorId": 500, "errorHandle": "unknown-error", "message": "Something unexpected happened" }

Example Usage

function handleRequestPermission() {
        VajroSDK.actions.requestLocationPermission();
}
// Can make use of location permission variable to check if permission is granted or not
:root {
  --primary-blue: #007AFF;
  --success-green: #34C759;
  --card-bg: #ffffff;
  --text-main: #1C1C1E;
  --text-sub: #8E8E93;
  --bg-color: #F2F2F7;
}
.sdk-dashboard {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  padding: 20px;
  min-height: 100vh;
}
.dashboard-header {
  margin-bottom: 24px;
}
.dashboard-header h2 {
  margin: 0;
  font-size: 24px;
  color: var(--text-main);
}
.dashboard-header p {
  margin: 4px 0 0;
  color: var(--text-sub);
}
.action-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.action-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transition: transform 0.2s ease;
}
.action-card:active {
  transform: scale(0.98);
  background: #FAFAFA;
}
.icon-wrapper {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}
.orders-bg { background: #E5F1FF; }
.camera-bg { background: #FFF4E5; }
.location-bg { background: #E5FFE9; }
.security-bg { background: #F2EBFF; }
.card-content h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text-main);
}
.card-content p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-sub);
}
.permission-card {
  border: 1px dashed #D1D1D6;
}
<div class="sdk-dashboard">
  <header class="dashboard-header">
    <h2>App Services</h2>
    <p>Manage your account and device features</p>
  </header>
  <div class="action-grid">
    <div class="action-card permission-card" onclick="handleRequestPermission()">
      <div class="icon-wrapper security-bg">🛡️</div>
      <div class="card-content">
        <h3>Enable Services</h3>
        <p>Grant location access for better features.</p>
      </div> 
    </div>
  </div>
</div>

Best Practices

  1. Transparency: Clearly explain the benefit of sharing location (e.g., "Find the nearest pickup point").
  2. Timing: Request location only when the user navigates to a map or store locator page.
  3. Check Variables: Use VajroSDK.variables.device.permissions.location to check the current state before triggering a prompt to avoid a redundant user experience.

Caveats

  1. On iOS, users may be prompted again by the OS after some time to confirm they still want to share their location in the background (if applicable).
  2. Accuracy may vary based on the user's hardware and environment (indoor vs. outdoor).