@ably/asset-tracking 中文文档教程

发布于 3年前 浏览 24 更新于 3年前

Ably Asset Tracking SDK for JavaScript

.github/workflows/check.yml

Overview

Ably 资产跟踪 SDK 提供了一种简单的方法来跟踪多个资产,实时位置更新由 Ably 实时网络和 Mapbox 导航 SDK 具有位置增强功能。

状态:这是 SDK 的预览版。 这意味着它包含最终 SDK 功能的一个子集,并且 API 可能会发生变化。 此 SDK 的最新版本可在该存储库的已发布部分中找到。

Ably Asset Tracking 是:

  • easy to integrate - comprising two complementary SDKs with easy to use APIs, available for multiple platforms:
  • Asset Publishing SDK, for embedding in apps running on the courier's device
  • Asset Subscribing SDK, for embedding in apps runnong on the customer's observing device
  • extensible - as Ably is used as the underlying transport, you have direct access to your data and can use Ably integrations for a wide range of applications in addition to direct realtime subscriptions - examples include:
  • passing to a 3rd party system
  • persistence for later retrieval
  • built for purpose - the APIs and underlying functionality are designed specifically to meet the requirements of a range of common asset tracking use-cases

此存储库包含用于 Web 的资产订阅 SDK。

Documentation

访问 Ably Asset Tracking 文档,获取完整的 API 参考和代码示例。

Useful Resources

Installation

要在您的应用程序中使用 Ably Asset Tracking,请将其安装为依赖项:

# If you are using NPM:
npm install @ably/asset-tracking

# If you are using Yarn:
yarn add @ably/asset-tracking

Usage

以下是如何使用 SDK 的示例:

import { Subscriber, Accuracy } from '@ably/asset-tracking';

const ablyOptions = {
  key: ABLY_API_KEY,
  clientId: CLIENT_ID,
};

// Define a callback to be notified when a location update is recieved.
const onLocationUpdate = (locationUpdate) => {
  console.log(`Location update recieved. Coordinates: ${locationUpdate.location.geometry.coordinates}`);
};

// Define a callback to be notified when the asset online status is updated.
const onStatusUpdate = (isOnline) => {
  console.log(`Status update: Publisher is now ${isOnline ? 'online' : 'offline'}`);
};

// Request a specific resolution to be considered by the publisher.
const resolution = {
  accuracy: Accuracy.High,
  desiredInterval: 1000,
  minimumDisplacement: 1,
};

// Initialise the subscriber.
const subscriber = new Subscriber({
  ablyOptions,
  onLocationUpdate,
  onStatusUpdate,
});

const trackingId = '<some application defined asset tracking identifier>';

(async () => {
  // Start tracking an asset using its tracking identifier.
  await subscriber.start(trackingId);

  // Request a new resolution to be considered by the publisher.
  await subscriber.sendChangeRequest({
    accuracy: Accuracy.Low,
    desiredInterval: 3000,
    minimumDisplacement: 5,
  });

  // Stop tracking the asset.
  await subscriber.stop();
})();

Example App

此存储库还包含一个示例应用程序,展示了如何使用 Ably Asset Tracking SDK:

Development

请参阅 贡献

Ably Asset Tracking SDK for JavaScript

.github/workflows/check.yml

Overview

Ably Asset Tracking SDKs provide an easy way to track multiple assets with realtime location updates powered by Ably realtime network and Mapbox Navigation SDK with location enhancement.

Status: this is a preview version of the SDK. That means that it contains a subset of the final SDK functionality, and the APIs are subject to change. The latest release of this SDK is available in the Released section of this repository.

Ably Asset Tracking is:

  • easy to integrate - comprising two complementary SDKs with easy to use APIs, available for multiple platforms:
  • Asset Publishing SDK, for embedding in apps running on the courier's device
  • Asset Subscribing SDK, for embedding in apps runnong on the customer's observing device
  • extensible - as Ably is used as the underlying transport, you have direct access to your data and can use Ably integrations for a wide range of applications in addition to direct realtime subscriptions - examples include:
  • passing to a 3rd party system
  • persistence for later retrieval
  • built for purpose - the APIs and underlying functionality are designed specifically to meet the requirements of a range of common asset tracking use-cases

This repository contains the Asset Subscribing SDK for Web.

Documentation

Visit the Ably Asset Tracking documentation for a complete API reference and code examples.

Useful Resources

Installation

To use Ably Asset Tracking in your app, install it as a dependency:

# If you are using NPM:
npm install @ably/asset-tracking

# If you are using Yarn:
yarn add @ably/asset-tracking

Usage

Here is an example of how the SDK can be used:

import { Subscriber, Accuracy } from '@ably/asset-tracking';

const ablyOptions = {
  key: ABLY_API_KEY,
  clientId: CLIENT_ID,
};

// Define a callback to be notified when a location update is recieved.
const onLocationUpdate = (locationUpdate) => {
  console.log(`Location update recieved. Coordinates: ${locationUpdate.location.geometry.coordinates}`);
};

// Define a callback to be notified when the asset online status is updated.
const onStatusUpdate = (isOnline) => {
  console.log(`Status update: Publisher is now ${isOnline ? 'online' : 'offline'}`);
};

// Request a specific resolution to be considered by the publisher.
const resolution = {
  accuracy: Accuracy.High,
  desiredInterval: 1000,
  minimumDisplacement: 1,
};

// Initialise the subscriber.
const subscriber = new Subscriber({
  ablyOptions,
  onLocationUpdate,
  onStatusUpdate,
});

const trackingId = '<some application defined asset tracking identifier>';

(async () => {
  // Start tracking an asset using its tracking identifier.
  await subscriber.start(trackingId);

  // Request a new resolution to be considered by the publisher.
  await subscriber.sendChangeRequest({
    accuracy: Accuracy.Low,
    desiredInterval: 3000,
    minimumDisplacement: 5,
  });

  // Stop tracking the asset.
  await subscriber.stop();
})();

Example App

This repository also contains an example app that showcases how the Ably Asset Tracking SDK can be used:

Development

see Contributing.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文