### Run the React example application Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/react/README.md Commands to install dependencies and start the development server from the monorepo root. ```bash yarn install yarn dev:react ``` -------------------------------- ### Configure iOS project Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/packages/client/react-native/README.md Run the setup helper to patch the Podfile and install iOS dependencies. ```bash npx @gebeta/react-native setup-ios cd ios && pod install ``` -------------------------------- ### start() Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Starts a new navigation session. ```APIDOC ## start(route, startOptions, locationProvider) ### Description Starts navigation along the provided route. ### Parameters - **route** (RouteData) - Route data containing geometry and instructions. - **startOptions** (NavigationStartOptions) - Options for starting navigation (userId, role, precision). - **locationProvider** (ILocationProvider) - Provider that supplies location data. ``` -------------------------------- ### Install Gebeta React SDK Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/installation.md Install the React-specific wrapper along with the core SDK. ```bash npm install @gebeta/react @gebeta/js ``` -------------------------------- ### Install Gebeta Node.js SDK Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/installation.md Install the server-side SDK for authentication and backend operations. ```bash npm install @gebeta/node ``` -------------------------------- ### start(route, options, locationProvider) Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/navigation-manager.md Initializes and starts the navigation process with the specified route, user options, and location provider. ```APIDOC ## start(route, options, locationProvider) ### Description Starts the navigation session using the provided route data, user configuration, and location provider. ### Signature `start(route: RouteData, options: { userId: string; role: string }, locationProvider: ILocationProvider): void` ``` -------------------------------- ### Install Gebeta JS SDK Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/README.md Install the browser SDK package using npm. ```bash npm install @gebeta/js ``` -------------------------------- ### NavigationManager Usage Example Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Example showing how to display a route and listen for navigation events. ```ts const route = await sdk.getDirections(origin, destination); sdk.displayRoute(route); sdk.navigation.on('progress', e => console.log('remaining:', e.remainingDistance)); sdk.navigation.on('arrive', () => console.log('Arrived!')); sdk.navigation.start(route, { userId: 'user-123' }, new BrowserLocationProvider()); ``` -------------------------------- ### Install Gebeta SDK via npm or yarn Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/installation.md Install the core SDK package using your preferred package manager. ```bash npm install @gebeta/js # or yarn add @gebeta/js ``` -------------------------------- ### Install dependencies Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/BUILD.md Run this command to install all necessary dependencies for the monorepo packages. ```bash npm install ``` -------------------------------- ### Install @gebeta/react-native dependencies Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/packages/client/react-native/README.md Install the SDK and the required MapLibre peer dependency. ```bash npm install @gebeta/react-native @maplibre/maplibre-react-native ``` -------------------------------- ### Get Directions Method and Usage Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Method signature and example for calculating a route between two points. ```ts getDirections( origin, destination, options?): Promise ``` ```ts const route = await sdk.getDirections( { lng: 38.74, lat: 9.02 }, { lng: 38.78, lat: 9.05 } ); sdk.displayRoute(route); ``` -------------------------------- ### Install Dependencies Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/react-native/README.md Run these commands from the monorepo root to install and build the necessary workspace packages. ```bash yarn install yarn workspace @gebeta/api build yarn workspace @gebeta/core build ``` -------------------------------- ### Setup Navigation Event Listeners Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/navigation-simulation.html Initializes event listeners for navigation lifecycle events such as start, stop, progress, and error handling. ```javascript map.once('style.load', setupNavigation); } }); function setupNavigation() { if (!gebetaMap || !gebetaMap.navigation) return; gebetaMap.navigation.on('start', function(event) { console.log('Navigation started:', event); isNavigating = true; currentRouteIndex = 0; updateNavUI(); document.getElementById('navInstruction').classList.add('active'); }); gebetaMap.navigation.on('stop', function(event) { console.log('Navigation stopped:', event); isNavigating = false; if (simulatedLocationProvider) { simulatedLocationProvider.stop(); simulatedLocationProvider = null; } updateNavUI(); document.getElementById('navInstruction').classList.remove('active'); }); gebetaMap.navigation.on('progress', function(event) { updateNavDetails(event); updateInstructionDisplay(event); updateRouteProgress(event); }); gebetaMap.navigation.on('stepchange', function(event) { console.log('Step changed:', event); updateNavDetails(event); updateInstructionDisplay(event); }); gebetaMap.navigation.on('offroute', function(event) { console.log('Off route:', event); var navInfo = document.getElementById('navInfo'); navInfo.classList.add('warning'); navInfo.classList.remove('active'); var statusIndicator = document.getElementById('statusIndicator'); statusIndicator.classList.add('warning'); statusIndicator.classList.remove('active'); }); gebetaMap.navigation.on('arrive', function(event) { console.log('Arrived at destination:', event); alert('You have arrived at your destination!'); stopNavigation(); }); gebetaMap.navigation.on('error', function(error) { console.error('Navigation error:', error); alert('Navigation error: ' + (error.message || error)); }); } ``` -------------------------------- ### Serve Examples Locally Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/README.md Command to serve the repository root, ensuring relative paths to the SDK distribution resolve correctly. ```bash npx serve . ``` -------------------------------- ### Install Gebeta API Types Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/installation.md Install the API types package directly for type-only usage in TypeScript projects. ```bash npm install @gebeta/api ``` -------------------------------- ### Start navigation with Gebeta SDK Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/navigation.md Initializes navigation using a route object, user configuration, and a location provider. ```js import { BrowserLocationProvider } from '@gebeta/js'; const route = await gebetaMap.getDirections(origin, destination); gebetaMap.navigation.start( route, { userId: 'driver-123', role: 'driver', }, new BrowserLocationProvider() ); ``` -------------------------------- ### Start Navigation Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/navigation-manager.md Initializes a navigation session with route data, user options, and a location provider. ```ts start( route: RouteData, options: { userId: string; role: string }, locationProvider: ILocationProvider ): void ``` -------------------------------- ### BrowserLocationProvider.start Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Starts the location tracking process and invokes the provided callback whenever a location update occurs. ```APIDOC ## start(onLocation) ### Description Begins tracking the user's location. ### Parameters - **onLocation** ((location) => void) - Required - A callback function that receives the location data. ``` -------------------------------- ### Define StartOptions type alias Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/api/namespaces/Navigation/namespaces/Navigation/namespaces/Types.md Represents the configuration options for starting a navigation session. ```ts type StartOptions: NavigationStartOptions; ``` -------------------------------- ### Configure Navigation Event Listeners Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/navigation-http.html Sets up handlers for navigation lifecycle events such as start, stop, progress, and arrival. ```javascript function setupNavigation() { if (!gebetaMap || !gebetaMap.navigation) return; gebetaMap.navigation.on('start', function(event) { console.log('Navigation started:', event); isNavigating = true; updateNavUI(); }); gebetaMap.navigation.on('stop', function(event) { console.log('Navigation stopped:', event); isNavigating = false; if (locationProvider) { locationProvider.stop(); locationProvider = null; } updateNavUI(); }); gebetaMap.navigation.on('progress', function(event) { updateNavDetails(event); }); gebetaMap.navigation.on('stepchange', function(event) { console.log('Step changed:', event); updateNavDetails(event); }); gebetaMap.navigation.on('offroute', function(event) { console.log('Off route:', event); var navInfo = document.getElementById('navInfo'); navInfo.classList.add('warning'); navInfo.classList.remove('active'); var statusIndicator = document.getElementById('statusIndicator'); statusIndicator.classList.add('warning'); statusIndicator.classList.remove('active'); }); gebetaMap.navigation.on('arrive', function(event) { console.log('Arrived at destination:', event); alert('You have arrived at your destination!'); stopNavigation(); }); gebetaMap.navigation.on('error', function(error) { console.error('Navigation error:', error); alert('Navigation error: ' + (error.message || error)); }); } ``` -------------------------------- ### Start Navigation with Low Precision Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/navigation-http.html Initializes the navigation session with low accuracy settings and updates the UI state. ```javascript Make sure gebeta-maps.umd.js is loaded.'); } locationProvider = BrowserLocationProvider.getInstance({ enableHighAccuracy: false }); gebetaMap.navigation.start( routeData, { userId: 'demo-user-' + Date.now(), role: 'driver', precision: 'low' }, locationProvider ); document.getElementById('btnStartNav').disabled = true; document.getElementById('btnStopNav').disabled = false; document.getElementById('navInfo').style.display = 'block'; updateNavUI(); } ``` -------------------------------- ### Route Retrieval and Navigation Start Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/navigation-http.html Handles fetching route data from the API and initiating the navigation session. ```javascript function getRoute() { if (!gebetaMap || !originCoords || !destCoords) return; var btn = document.getElementById('btnGetRoute'); btn.disabled = true; btn.textContent = 'Loading...'; gebetaMap.getDirections(originCoords, destCoords, {}) .then(function(data) { routeData = data; gebetaMap.displayRoute(data, { showMarkers: false }); document.getElementById('btnStartNav').disabled = false; btn.textContent = 'Get Route'; }) .catch(function(err) { console.error(err); alert('Route failed: ' + (err.message || err)); btn.disabled = false; btn.textContent = 'Get Route'; }); } function startNavigation() { if (!gebetaMap || !gebetaMap.navigation || !routeData) return; if (!navigator.geolocation) { alert('Geolocation is not supported by your browser'); return; } if (typeof BrowserLocationProvider === 'undefined') { throw new Error('BrowserLocationProvider is not available. ``` -------------------------------- ### Navigation Simulation JavaScript Logic Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/navigation-simulation.html JavaScript initialization for the Gebeta Maps SDK, including map setup, event handling for markers, and navigation state management. ```javascript var gebetaMap; var map; var currentMode = null; var originCoords = null; var destCoords = null; var originMarker = null; var destMarker = null; var routeData = null; var isNavigating = false; var simulatedLocationProvider = null; var simulationSpeed = 1; var currentRouteIndex = 0; var fullRouteCoordinates = null; var ORIGIN_ICON = 'https://cdn-icons-png.flaticon.com/512/1828/1828640.png'; var DEST_ICON = 'https://cdn-icons-png.flaticon.com/512/3081/3081559.png'; var instructionIcons = { 1: '→', 2: '↗', 3: '→', 4: '↘', 5: '↓', 6: '↙', 7: '←', 8: '↖', 9: '↑', 14: '↺', 15: '↻', }; document.addEventListener('DOMContentLoaded', function() { var config = loadConfig(); var auth = (config.GEBETA_ACCESS_TOKEN && config.GEBETA_REFRESH_TOKEN) ? { accessToken: config.GEBETA_ACCESS_TOKEN, refreshToken: config.GEBETA_REFRESH_TOKEN } : null; var apiKey = auth ? null : config.GEBETA_API_KEY; if (!apiKey || apiKey === 'YOUR_API_KEY') { console.warn('Set GEBETA_API_KEY in config.js'); } gebetaMap = new GebetaMaps(auth ? { auth: auth } : { apiKey: apiKey }); map = gebetaMap.init({ container: 'map', center: [38.7685, 9.0161], zoom: 12, navigationControl: true, }); map.on('click', function(e) { var lngLat = e.lngLat; var lat = lngLat.lat; var lng = lngLat.lng; if (currentMode === 'origin') { if (originMarker) originMarker.remove(); originMarker = addPinMarker(lng, lat, ORIGIN_ICON); originCoords = { lat: lat, lng: lng }; updateCoordsDisplay(); setMode(null); document.getElementById('btnDest').focus(); } else if (currentMode === 'destination') { if (destMarker) destMarker.remove(); destMarker = addPinMarker(lng, lat, DEST_ICON); destCoords = { lat: lat, lng: lng }; updateCoordsDisplay(); setMode(null); } }); if (map.isStyleLoaded && map.isStyleLoaded()) { setupNavigation(); } else { ``` -------------------------------- ### Start location tracking Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Initiates location tracking by providing a callback function to handle location updates. ```ts start(onLocation): void ``` -------------------------------- ### Implement Authentication Endpoint Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/gebeta-auth.md Example usage of the authenticate method within an Express-style POST route. ```ts const auth = new GebetaAuth({ serverToken: process.env.GEBETA_SERVER_TOKEN! }); app.post('/auth', async (req, res) => { const credentials = await auth.authenticate(req.body.clientToken); res.json(credentials); // { accessToken, refreshToken } }); ``` -------------------------------- ### Retrieve Route Summary Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/gebeta-maps.md Get summary information for the currently loaded route. ```ts getRouteSummary(): { distance?: string | number | null; duration?: string | number | null; origin?: { lat: number; lng: number }; destination?: { lat: number; lng: number }; waypoints?: { lat: number; lng: number }[]; } | null ``` -------------------------------- ### Render GebetaMap Component Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/react/globals.md Example usage of the GebetaMap component within a React application. ```jsx import { GebetaMap } from '@gebeta/react'; const auth = { accessToken: '...', refreshToken: '...' }; const style = { width: '100vw', height: '100vh' }; function App() { return (
console.log('Map ready', map)} />
); } ``` -------------------------------- ### Get Clustering Options Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Retrieves the current normalized configuration options for the clustering manager. ```ts getOptions(): NormalizedClusteringOptions ``` -------------------------------- ### Get BrowserLocationProvider instance Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Retrieves the singleton instance of the BrowserLocationProvider, optionally accepting configuration options. ```ts static getInstance(options?): BrowserLocationProvider ``` -------------------------------- ### Get Route Summary Method Signature Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Method signature for retrieving summary data for the current route. ```ts getRouteSummary(): null | object ``` -------------------------------- ### Get Current Route Method Signature Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Method signature for retrieving the currently active route. ```ts getCurrentRoute(): null | RouteData ``` -------------------------------- ### Add a geofence Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/fencing.md Defines a new polygon fence by providing an ID and a list of coordinates. Ensure the polygon is closed by repeating the starting coordinate at the end. ```js gebetaMap.fencing.addFence({ id: 'zone-1', coordinates: [ [38.76, 9.01], [38.78, 9.01], [38.78, 9.03], [38.76, 9.03], [38.76, 9.01], // close the polygon ], }); ``` -------------------------------- ### Initialize GebetaMaps Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Demonstrates initializing the SDK using either service account authentication or a legacy API key. ```ts // Service account auth (recommended) const sdk = new GebetaMaps({ auth: { accessToken: '...', refreshToken: '...' } }); const map = sdk.init({ container: '#map', center: [38.74, 9.02], zoom: 12 }); // Legacy API key (deprecated) const sdk = new GebetaMaps({ apiKey: 'your-api-key' }); ``` -------------------------------- ### init(options) Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Initializes the map and mounts it to a DOM element. All SDK managers are created after the map style finishes loading. ```APIDOC ## init(options) ### Description Initialize the map and mount it to a DOM element. Do not call manager methods until the map `style.load` event fires. ### Parameters - **options** (GebetaMapsInitOptions) - Required - Initialization options ### Returns - **Map** - The underlying MapLibre GL Map instance ``` -------------------------------- ### Initialize Gebeta Maps SDK Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/README.md Initialize the SDK with authentication credentials and mount the map to a container. ```js import { GebetaMaps } from '@gebeta/js'; const sdk = new GebetaMaps({ auth: { accessToken: '...', refreshToken: '...' } }); const map = sdk.init({ container: '#map', center: [38.74, 9.02], zoom: 12 }); ``` -------------------------------- ### init(options) Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/gebeta-maps.md Initializes and renders the map, returning the underlying MapLibre map instance. ```APIDOC ## init(options) ### Description Initializes and renders the map. Returns the underlying MapLibre Map instance. ### Parameters - **options** (Object) - Required - Configuration including container, center coordinates, zoom level, map style, and navigation controls. ``` -------------------------------- ### Get Current Step Index Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/navigation-manager.md Retrieves the index of the current step in the route. ```ts getCurrentStepIndex(): number ``` -------------------------------- ### Initialize GebetaMaps with legacy API key Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/authentication.md Use this only for backwards compatibility; migration to service account auth is recommended. ```js const gebetaMap = new GebetaMaps({ apiKey: 'your-api-key', }); ``` -------------------------------- ### new GebetaMaps(options) Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/gebeta-maps.md Initializes a new instance of the GebetaMaps SDK with authentication and configuration options. ```APIDOC ## new GebetaMaps(options) ### Description Creates a new instance of the GebetaMaps SDK. ### Parameters - **options** (ConstructorOptions) - Required - Configuration object containing auth tokens, API keys, clustering settings, and client ID preferences. ``` -------------------------------- ### Run Application Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/react-native/README.md Commands to launch the application on iOS or Android platforms. ```bash # iOS — first time only: cd apps/react-native/ios && bundle install && bundle exec pod install && cd - yarn workspace gebeta-rn-example ios # Android: yarn workspace gebeta-rn-example android ``` -------------------------------- ### Calculate and display routes with GebetaMaps Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/directions-manager.md Initializes the SDK and demonstrates the workflow for calculating a route and rendering it on the map container. ```js import { GebetaMaps } from '@gebeta/js'; const sdk = new GebetaMaps({ auth: { accessToken, refreshToken } }); sdk.init({ container: 'map' }); // Calculate a route const route = await sdk.getDirections(origin, destination); // Display it on the map sdk.displayRoute(route, { showMarkers: true }); // Clear it sdk.clearRoute(); ``` -------------------------------- ### Initialize and use GebetaAuth Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/node/index.md Configure the SDK with your server token and implement an authentication endpoint to issue tokens to the frontend. ```ts import { GebetaAuth } from '@gebeta/node'; const auth = new GebetaAuth({ serverToken: process.env.GEBETA_SERVER_TOKEN! }); // Express endpoint — receives clientToken from the frontend app.post('/auth', async (req, res) => { const credentials = await auth.authenticate(req.body.clientToken); res.json(credentials); // { accessToken, refreshToken } }); ``` -------------------------------- ### Get Error Domain Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/api/namespaces/API/namespaces/Errors/namespaces/Utils.md Retrieves the error domain from an unknown error, returning null if it is not a GebetaError. ```ts function getErrorDomain(error): ErrorDomain | null ``` -------------------------------- ### Get Error Code Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/api/namespaces/API/namespaces/Errors/namespaces/Utils.md Retrieves the error code from an unknown error, returning null if it is not a GebetaError. ```ts function getErrorCode(error): ErrorCode | null ``` -------------------------------- ### Build packages Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/BUILD.md Commands to build the entire project or specifically the API package. ```bash npm run build ``` ```bash npm run build:api ``` -------------------------------- ### Include Gebeta SDK via CDN Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/installation.md Add the SDK to your HTML using script tags. Pinned versions are recommended for production stability. ```html ``` -------------------------------- ### Importing the full SDK Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/tree-shaking.md Importing from the root package pulls in the entire SDK, which may result in a larger bundle size. ```js // Pulls in the full SDK (~300 kB) import { GeocodingManager } from '@gebeta/js'; ``` -------------------------------- ### new GebetaAuth(options) Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/node/globals.md Initializes a new instance of the GebetaAuth helper using a secret server token. ```APIDOC ## new GebetaAuth(options) ### Description Initializes the authentication helper with the required server-side credentials. ### Parameters - **options** (object) - Required - **serverToken** (string) - Required: Secret server token from the Gebeta dashboard. Keep this on your backend; never expose it to clients. ``` -------------------------------- ### Get Map Method Signature Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Method signature for accessing the underlying MapLibre GL map instance. ```ts getMap(): null | Map ``` -------------------------------- ### Initialize Map and Fencing Logic Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/fence-styling.html Initializes the GebetaMaps instance and sets up the fencing environment once the map style is loaded. ```javascript var gebetaMap; var map; document.addEventListener('DOMContentLoaded', function() { var config = loadConfig(); var auth = (config.GEBETA_ACCESS_TOKEN && config.GEBETA_REFRESH_TOKEN) ? { accessToken: config.GEBETA_ACCESS_TOKEN, refreshToken: config.GEBETA_REFRESH_TOKEN } : null; var apiKey = auth ? null : config.GEBETA_API_KEY; if (!apiKey || apiKey === 'YOUR_API_KEY') { console.warn('Set GEBETA_API_KEY in config.js'); } gebetaMap = new GebetaMaps(auth ? { auth: auth } : { apiKey: apiKey }); map = gebetaMap.init({ container: 'map', center: [38.7685, 9.0161], zoom: 15, navigationControl: true, }); function setupFencing() { updateStyle(); } if (map.isStyleLoaded && map.isStyleLoaded()) { setupFencing(); } else { map.once('style.load', setupFencing); } }); ``` -------------------------------- ### Initialize GebetaAuth Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/node-auth.md Initialize the authentication client using your server token from environment variables. ```typescript import { GebetaAuth } from '@gebeta/node'; const auth = new GebetaAuth({ serverToken: process.env.GEBETA_SERVER_TOKEN! }); ``` -------------------------------- ### Initialize Gebeta Map via CDN Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/installation.md Initialize the map instance globally after loading the SDK script. ```html
``` -------------------------------- ### gebetaMap.navigation.start Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/navigation.md Initiates turn-by-turn navigation using a calculated route, user configuration, and a location provider. ```APIDOC ## gebetaMap.navigation.start(route, options, locationProvider) ### Description Starts the navigation session for a given route. Requires a route object, user identification options, and a location provider instance. ### Parameters - **route** (Object) - Required - The route object obtained from gebetaMap.getDirections. - **options** (Object) - Required - Configuration object containing `userId` (string) and `role` (string). - **locationProvider** (Object) - Required - An instance of a location provider (e.g., BrowserLocationProvider). ``` -------------------------------- ### Toggle SDK Source Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/README.md Commands to switch between using the local SDK build and the published CDN version. ```bash # Use local build (default — for development) yarn examples:local # Use published CDN version (to test against released SDK) yarn examples:npm ``` -------------------------------- ### Initialize GebetaMaps with service account tokens Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/authentication.md Pass the tokens retrieved from your backend to the SDK; token refresh is handled automatically. ```js const { accessToken, refreshToken } = await fetch('/auth', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientToken: 'YOUR_CLIENT_TOKEN' }), }).then(r => r.json()); const gebetaMap = new GebetaMaps({ auth: { accessToken, refreshToken }, }); ``` -------------------------------- ### Navigation Logic and Event Handling Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/navigation.html JavaScript implementation for initializing the map, handling user clicks for origin/destination, and setting up navigation event listeners. ```javascript var gebetaMap; var map; var currentMode = null; var originCoords = null; var destCoords = null; var originMarker = null; var destMarker = null; var routeData = null; var isNavigating = false; var locationProvider = null; var ORIGIN_ICON = 'https://cdn-icons-png.flaticon.com/512/1828/1828640.png'; var DEST_ICON = 'https://cdn-icons-png.flaticon.com/512/3081/3081559.png'; document.addEventListener('DOMContentLoaded', function() { var config = loadConfig(); var auth = (config.GEBETA_ACCESS_TOKEN && config.GEBETA_REFRESH_TOKEN) ? { accessToken: config.GEBETA_ACCESS_TOKEN, refreshToken: config.GEBETA_REFRESH_TOKEN } : null; var apiKey = auth ? null : config.GEBETA_API_KEY; if (!apiKey || apiKey === 'YOUR_API_KEY') { console.warn('Set GEBETA_API_KEY in config.js'); } gebetaMap = new GebetaMaps(auth ? { auth: auth } : { apiKey: apiKey }); map = gebetaMap.init({ container: 'map', center: [38.7685, 9.0161], zoom: 12, navigationControl: true, }); map.on('click', function(e) { var lngLat = e.lngLat; var lat = lngLat.lat; var lng = lngLat.lng; if (currentMode === 'origin') { if (originMarker) originMarker.remove(); originMarker = addPinMarker(lng, lat, ORIGIN_ICON); originCoords = { lat: lat, lng: lng }; updateCoordsDisplay(); setMode(null); document.getElementById('btnDest').focus(); } else if (currentMode === 'destination') { if (destMarker) destMarker.remove(); destMarker = addPinMarker(lng, lat, DEST_ICON); destCoords = { lat: lat, lng: lng }; updateCoordsDisplay(); setMode(null); } }); if (map.isStyleLoaded && map.isStyleLoaded()) { setupNavigation(); } else { map.once('style.load', setupNavigation); } }); function setupNavigation() { if (!gebetaMap || !gebetaMap.navigation) return; gebetaMap.navigation.on('start', function(event) { console.log('Navigation started:', event); isNavigating = true; updateNavUI(); }); gebetaMap.navigation.on('stop', function(event) { console.log('Navigation stopped:', event); isNavigating = false; if (locationProvider) { locationProvider.stop(); locationProvider = null; } updateNavUI(); }); gebetaMap.navigation.on('progress', function(event) { updateNavDetails(event); }); gebetaMap.navigation.on('stepchange', function(event) { console.log('Step changed:', event); updateNavDetails(event); }); gebetaMap.navigation.on('offroute', function(event) { console.log('Off route:', event); var navInfo = document.getElementById('navInfo'); navInfo.classList.add('warning'); navInfo.classList.remove('active'); var statusIndicator = document.getElementById('statusIndicator'); statusIndicator.classList.add('warning'); statusIndicator.classList.remove('active'); }); gebetaMap.navigation.on('arrive', function(event) { console.log('Arrived at destination:', event); alert('You have arrived at your destination!'); stopNavigation(); }); gebetaMap.navigation.on('error', function(error) { console.error('Navigation error:', error); alert('Navigation error: ' + (error.message || error)); }); } function setMode(mode) { currentMode = mode; ``` -------------------------------- ### Initialize and Render Map Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/gebeta-maps.md Use the init method to render the map into a container and return the MapLibre instance. ```ts init(options: { container: string | HTMLElement; center?: [number, number]; // [lng, lat], default: Addis Ababa zoom?: number; // default: 12 style?: string; // map style URL navigationControl?: boolean; // show zoom/compass controls }): MapLibreMap ``` -------------------------------- ### Initialize GebetaMap component Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/react.md Basic implementation of the GebetaMap component with authentication and initial center coordinates. ```jsx import { GebetaMap } from '@gebeta/react'; const auth = { accessToken, refreshToken }; const mapStyle = { width: '100%', height: '500px' }; const center = [38.7685, 9.0161]; function App() { return ( { console.log('Map ready'); }} /> ); } ``` -------------------------------- ### Initialize GeocodingManager Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/geocoding-manager.md Shows how to access the manager through the main SDK or instantiate it independently using AuthManager. ```js // With full SDK import { GebetaMaps } from '@gebeta/js'; const geocoder = gebetaMap.geocodingManager; // Standalone (tree-shakeable) import { GeocodingManager, AuthManager } from '@gebeta/js/geocoding'; const geocoder = new GeocodingManager(new AuthManager({ accessToken, refreshToken })); ``` -------------------------------- ### Access managers via onLoad Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/react.md Demonstrates the onLoad callback structure for map initialization. ```jsx const auth = { accessToken, refreshToken }; const mapStyle = { width: '100%', height: '500px' }; function MapWithGeocoding() { return ( { // clustering is null unless clustering.enabled is set }} /> ); } ``` -------------------------------- ### Initialize Map and Handle Click Events Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/directions.html Initializes the Gebeta map instance and sets up click listeners to capture origin and destination coordinates. ```javascript var gebetaMap; var map; var currentMode = null; var originCoords = null; var destCoords = null; var originMarker = null; var destMarker = null; var ORIGIN_ICON = 'https://cdn-icons-png.flaticon.com/512/1828/1828640.png'; var DEST_ICON = 'https://cdn-icons-png.flaticon.com/512/3081/3081559.png'; document.addEventListener('DOMContentLoaded', function() { var config = loadConfig(); var auth = (config.GEBETA_ACCESS_TOKEN && config.GEBETA_REFRESH_TOKEN) ? { accessToken: config.GEBETA_ACCESS_TOKEN, refreshToken: config.GEBETA_REFRESH_TOKEN } : null; var apiKey = auth ? null : config.GEBETA_API_KEY; if (!apiKey && !auth.accessToken) { console.warn('Set authentication configuration in config.js'); } gebetaMap = new GebetaMaps(auth ? { auth: auth, enableClientId: true } : { apiKey: apiKey }); map = gebetaMap.init({ container: 'map', center: [38.7685, 9.0161], zoom: 12, navigationControl: true, }); map.on('click', function(e) { var lngLat = e.lngLat; var lat = lngLat.lat; var lng = lngLat.lng; if (currentMode === 'origin') { if (originMarker) originMarker.remove(); originMarker = addPinMarker(lng, lat, ORIGIN_ICON); originCoords = { lat: lat, lng: lng }; updateCoordsDisplay(); setMode(null); document.getElementById('btnDest').focus(); } else if (currentMode === 'destination') { if (destMarker) destMarker.remove(); destMarker = addPinMarker(lng, lat, DEST_ICON); destCoords = { lat: lat, lng: lng }; updateCoordsDisplay(); setMode(null); } }); }); ``` -------------------------------- ### Configure API Key Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/react-native/README.md Set the Gebeta API key in the environment for the Metro bundler to access. ```bash export GEBETA_API_KEY=your-key-here ``` -------------------------------- ### Initialize Gebeta Map and Fencing Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/fencing.html Initializes the map instance and sets up event listeners for fencing controls. ```javascript var gebetaMap; var map; var isDrawing = false; document.addEventListener('DOMContentLoaded', function() { var config = loadConfig(); var auth = (config.GEBETA_ACCESS_TOKEN && config.GEBETA_REFRESH_TOKEN) ? { accessToken: config.GEBETA_ACCESS_TOKEN, refreshToken: config.GEBETA_REFRESH_TOKEN } : null; var apiKey = auth ? null : config.GEBETA_API_KEY; if (!apiKey || apiKey === 'YOUR_API_KEY') { console.warn('Set GEBETA_API_KEY in config.js'); } gebetaMap = new GebetaMaps(auth ? { auth: auth } : { apiKey: apiKey }); map = gebetaMap.init({ container: 'map', center: [38.7636, 9.0054], zoom: 13, navigationControl: true, }); const startDrawingBtn = document.getElementById('startDrawing'); const stopDrawingBtn = document.getElementById('stopDrawing'); const closeFenceBtn = document.getElementById('closeFence'); const clearCurrentBtn = document.getElementById('clearCurrent'); const clearAllBtn = document.getElementById('clearAll'); const statusEl = document.getElementById('status'); const pointCountEl = document.getElementById('pointCount'); const fenceCountEl = document.getElementById('fenceCount'); function updateUI() { if (!gebetaMap || !gebetaMap.fencing) return; const fencing = gebetaMap.fencing; isDrawing = fencing.isDrawingFence(); const points = fencing.getCurrentFencePoints(); const fences = fencing.getFences(); startDrawingBtn.disabled = isDrawing; stopDrawingBtn.disabled = !isDrawing; closeFenceBtn.disabled = !isDrawing || points.length < 3; clearCurrentBtn.disabled = !isDrawing; statusEl.textContent = isDrawing ? 'Drawing' : 'Not drawing'; pointCountEl.textContent = points.length; fenceCountEl.textContent = fences.length; } function setupFencing() { startDrawingBtn.addEventListener('click', () => { gebetaMap.fencing.startDrawing(); updateUI(); }); stopDrawingBtn.addEventListener('click', () => { gebetaMap.fencing.stopDrawing(); updateUI(); }); closeFenceBtn.addEventListener('click', () => { const fence = gebetaMap.fencing.closeFence(); if (fence) { console.log('Fence completed:', fence); } updateUI(); }); clearCurrentBtn.addEventListener('click', () => { gebetaMap.fencing.clearCurrentFence(); updateUI(); }); clearAllBtn.addEventListener('click', () => { gebetaMap.fencing.clearAllFences(); updateUI(); }); gebetaMap.fencing.on('fenceCompleted', (event) => { console.log('Fence completed event:', event); updateUI(); }); setInterval(updateUI, 500); updateUI(); } if (map.isStyleLoaded && map.isStyleLoaded()) { setupFencing(); } else { map.once('style.load', setupFencing); } }); ``` -------------------------------- ### Initialize GebetaMaps with Service Account Tokens Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/migration.md The recommended method for initializing the map instance using tokens retrieved from a backend authentication endpoint. ```js const { accessToken, refreshToken } = await fetch('/auth', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientToken: 'YOUR_CLIENT_TOKEN' }), }).then(r => r.json()); const gebetaMap = new GebetaMaps({ auth: { accessToken, refreshToken } }); ``` -------------------------------- ### Consume Authentication on Frontend Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/node-auth.md Fetch credentials from the backend and initialize the map instance. ```javascript async function initMap() { const { accessToken, refreshToken } = await fetch('/auth', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientToken: 'YOUR_CLIENT_TOKEN' }), }).then(r => r.json()); const gebetaMap = new GebetaMaps({ auth: { accessToken, refreshToken } }); gebetaMap.init({ container: 'map' }); } ``` -------------------------------- ### Initialize a basic map Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/map-setup.md Initializes the GebetaMaps instance with authentication credentials and basic map configuration. ```js import { GebetaMaps } from '@gebeta/js'; const gebetaMap = new GebetaMaps({ auth: { accessToken, refreshToken }, }); const map = gebetaMap.init({ container: 'map', // DOM element ID or HTMLElement center: [38.7685, 9.0161], // [lng, lat] — defaults to Addis Ababa zoom: 12, navigationControl: true, // adds zoom/compass controls }); ``` -------------------------------- ### Initialize Map Method Signature Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Method signature for initializing the map and mounting it to the DOM. ```ts init(options): Map ``` -------------------------------- ### Configure environment variables for authentication Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/authentication.md Store sensitive tokens in environment variables rather than hardcoding them in source files. ```bash # .env (backend) GEBETA_SERVER_TOKEN=your-server-token ``` ```js // Load with dotenv import 'dotenv/config'; const auth = new GebetaAuth({ serverToken: process.env.GEBETA_SERVER_TOKEN }); ``` -------------------------------- ### Using subpath imports Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/tree-shaking.md Importing from specific subpaths allows for smaller bundle sizes by including only the necessary modules. ```js // Only geocoding (~45 kB) import { GeocodingManager } from '@gebeta/js/geocoding'; // Only directions import { DirectionsManager } from '@gebeta/js/directions'; // Only clustering import { ClusteringManager } from '@gebeta/js/clustering'; // Only navigation import { NavigationManager } from '@gebeta/js/navigation'; // Only fencing import { FenceManager } from '@gebeta/js/fencing'; ``` -------------------------------- ### getPlatform() Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Returns the platform context for advanced use cases. ```APIDOC ## getPlatform() ### Description Returns the platform context (map adapter, marker/popup factories). Useful for advanced use cases that need direct access to the underlying adapters. ### Returns - **PlatformContext** - The platform context object. ``` -------------------------------- ### Initialize GebetaMap component Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/react/index.md Render the map component by providing authentication tokens and a container style. ```tsx import { GebetaMap } from '@gebeta/react'; function App() { return ( { // Full access to GebetaMaps, MapLibre map, and platform adapters }} /> ); } ``` -------------------------------- ### on() Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Registers an event listener for navigation events. ```APIDOC ## on(event, callback) ### Description Registers a callback function for a specific navigation event. ### Parameters - **event** (K) - The event name to listen for. - **callback** (Function) - The function to execute when the event occurs. ``` -------------------------------- ### Configure fence settings Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Methods to set global styling and proximity thresholds for fences. ```ts setDefaultStyle(style): void ``` ```ts setProximityThreshold(meters): void ``` -------------------------------- ### Auditing bundle size Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/tree-shaking.md Run the bundle analyzer to inspect included modules and their respective sizes. ```bash yarn bundle:audit ``` -------------------------------- ### Initialize GebetaMaps Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/gebeta-maps.md Instantiate the GebetaMaps class using the constructor options. ```ts new GebetaMaps(options: ConstructorOptions) ``` -------------------------------- ### Run all tests in @gebeta/maps-js Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/testing.md Executes the full test suite for the maps-js package. ```bash yarn workspace @gebeta/maps-js test ``` -------------------------------- ### BrowserLocationProvider.getInstance Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Retrieves the singleton instance of the BrowserLocationProvider, optionally accepting configuration options. ```APIDOC ## static getInstance(options?) ### Description Returns the singleton instance of the BrowserLocationProvider class. ### Parameters - **options** (LocationProviderOptions) - Optional - Configuration options for the location provider. ### Returns - **BrowserLocationProvider** - The singleton instance of the provider. ``` -------------------------------- ### Initialize Map with Clustering Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/clustering.html Initializes the GebetaMaps instance with clustering options enabled and sets up event listeners for map interactions. ```javascript var gebetaMap; var map; var markerCounter = 0; document.addEventListener('DOMContentLoaded', function() { var config = loadConfig(); var auth = (config.GEBETA_ACCESS_TOKEN && config.GEBETA_REFRESH_TOKEN) ? { accessToken: config.GEBETA_ACCESS_TOKEN, refreshToken: config.GEBETA_REFRESH_TOKEN } : null; var apiKey = auth ? null : config.GEBETA_API_KEY; if (!auth && (!apiKey || apiKey === 'YOUR_API_KEY')) { console.warn('Set GEBETA_ACCESS_TOKEN/GEBETA_REFRESH_TOKEN or GEBETA_API_KEY in config.js'); } var clusteringOpts = { enabled: true, radius: 50, maxZoom: 16, showClusterCount: true, }; gebetaMap = new GebetaMaps(auth ? { auth: auth, clustering: clusteringOpts } : { apiKey: apiKey, clustering: clusteringOpts } ); map = gebetaMap.init({ container: 'map', center: [38.7685, 9.0161], zoom: 12, navigationControl: true, }); map.on('moveend', updateStats); map.on('zoomend', updateStats); }); ``` -------------------------------- ### getOptions() Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Retrieves the current clustering configuration. ```APIDOC ## getOptions() ### Description Returns the current clustering options. ### Returns - **NormalizedClusteringOptions** - Current clustering options ``` -------------------------------- ### Initialize ClusteringManager Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Constructor signature for creating a new ClusteringManager instance. ```ts new ClusteringManager( mapAdapter, markerFactory, popupFactory, options): ClusteringManager ``` -------------------------------- ### Include Gebeta Maps via CDN Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/README.md Load the Gebeta Maps UMD bundle directly in an HTML file. ```html ``` -------------------------------- ### Initialize GebetaAuth Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/node/globals.md Constructor signature for creating a new GebetaAuth instance. ```ts new GebetaAuth(options): GebetaAuth ``` -------------------------------- ### gebetaMap.navigation.on Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/navigation.md Registers event listeners for navigation updates such as progress, off-route detection, and arrival. ```APIDOC ## gebetaMap.navigation.on(event, callback) ### Description Subscribes to navigation events to receive real-time updates. ### Events - **progress**: Emits an event object containing `currentStep`, `remainingDistance` (meters), and `remainingTime` (seconds). - **offroute**: Emits when the user deviates from the planned route. - **arrive**: Emits when the destination is reached. ``` -------------------------------- ### Geocoding Logic and Map Initialization Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/apps/js/geocoding.html JavaScript implementation for initializing the Gebeta map and handling forward and reverse geocoding requests. ```javascript var gebetaMap; var map; var resultMarkers = []; document.addEventListener('DOMContentLoaded', function() { var config = loadConfig(); var auth = (config.GEBETA_ACCESS_TOKEN && config.GEBETA_REFRESH_TOKEN) ? { accessToken: config.GEBETA_ACCESS_TOKEN, refreshToken: config.GEBETA_REFRESH_TOKEN } : null; var apiKey = auth ? null : config.GEBETA_API_KEY; if (!apiKey || apiKey === 'YOUR_API_KEY') { console.warn('Set GEBETA_API_KEY in config.js'); } gebetaMap = new GebetaMaps(auth ? { auth: auth } : { apiKey: apiKey }); map = gebetaMap.init({ container: 'map', center: [38.7685, 9.0161], zoom: 12, navigationControl: true, }); }); function clearResultMarkers() { resultMarkers.forEach(function(m) { m.remove(); }); resultMarkers = []; } function showResults(results) { var el = document.getElementById('results'); el.innerHTML = ''; clearResultMarkers(); if (!results || results.length === 0) { el.innerHTML = '
No results.
'; return; } results.forEach(function(item, idx) { var name = item.name || 'Unknown'; var lat = item.lngLat && item.lngLat.lat != null ? item.lngLat.lat : null; var lng = item.lngLat && item.lngLat.lng != null ? item.lngLat.lng : null; var div = document.createElement('div'); div.className = 'result-item'; div.innerHTML = '' + name + '
' + (lat != null && lng != null ? lat.toFixed(5) + ', ' + lng.toFixed(5) : '') + ''; if (lat != null && lng != null) { var platform = gebetaMap.getPlatform(); var marker = platform.markerFactory .createMarker({}) .setLngLat({ lng: lng, lat: lat }) .addTo(platform.mapAdapter); resultMarkers.push(marker); div.onclick = (function(lng, lat) { return function() { gebetaMap.getPlatform().mapAdapter.easeTo({ center: [lng, lat], zoom: 16 }); }; })(lng, lat); } el.appendChild(div); }); if (results[0] && results[0].lngLat) { var c = results[0].lngLat; gebetaMap.getPlatform().mapAdapter.easeTo({ center: [c.lng, c.lat], zoom: 14 }); } } function doGeocode() { var place = document.getElementById('placeInput').value.trim(); if (!place) { alert('Enter a place name.'); return; } gebetaMap.geocodingManager.geocode(place) .then(showResults) .catch(function(err) { showResults([]); alert('Geocoding failed: ' + (err.message || err)); }); } function doReverseGeocode() { var lat = parseFloat(document.getElementById('latInput').value); var lon = parseFloat(document.getElementById('lonInput').value); if (isNaN(lat) || isNaN(lon)) { alert('Enter valid latitude and longitude.'); return; } gebetaMap.geocodingManager.reverseGeocode({ lat: lat, lng: lon }) .then(showResults) .catch(function(err) { showResults([]); alert('Reverse geocoding failed: ' + (err.message || err)); }); } ``` -------------------------------- ### Initialize GebetaMaps with API Key Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/migration.md The deprecated method for initializing the map instance using a static API key. ```js const gebetaMap = new GebetaMaps({ apiKey: 'your-api-key' }); ``` -------------------------------- ### Initialize Geocoding Manager Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/guide/node-geocoding.md Configure the GeocodingManager with authentication credentials using environment variables. ```ts import { GeocodingManager, AuthManager } from '@gebeta/js/geocoding'; const geocoder = new GeocodingManager( new AuthManager({ accessToken: process.env.GEBETA_ACCESS_TOKEN!, refreshToken: process.env.GEBETA_REFRESH_TOKEN!, }) ); ``` -------------------------------- ### Construct GebetaMaps Instance Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/globals.md Constructor signature for creating a new map instance. Provide either apiKey or auth, but not both. ```ts new GebetaMaps(options): GebetaMaps ``` -------------------------------- ### Configure authentication Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/api/@gebeta/js/index.md Pass tokens generated by the backend to the GebetaMaps constructor. ```js const gebetaMap = new GebetaMaps({ auth: { accessToken, refreshToken } }); ``` -------------------------------- ### Import GebetaMap component Source: https://github.com/afrigebeta/gebeta-sdk-js/blob/main/docs/reference/gebeta-map-component.md Import the component from the @gebeta/react package. ```jsx import { GebetaMap } from '@gebeta/react'; ```