• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Using startAbilityByType to Start a Navigation Application
2
3
4This topic describes how to open the vertical domain panel of navigation applications.
5
6## Parameters on the Navigation Application Panel
7
8If the **type** field in **startAbilityByType** is set to **navigation**, three intent scenarios are supported: route planning, navigation, and place search. The corresponding **wantParam** parameter contains the following properties.
9
10> **NOTE**
11>
12> The GCJ-02 coordinate system is used for the longitude and latitude in this document.
13
14- Route planning scenarios
15
16    | Name              | Type                  | Mandatory| Description                                                |
17    | -------------------- | ---------------------- | ---- | ---------------------------------------------------- |
18    | sceneType            | number                 | No  | Intent scene, which indicates the purpose of the current request. The default value is **1**. In route planning scenarios, set it to **1** or leave it empty.                  |
19    | originName           | string                 | No  | Name of the source.                                            |
20    | originLatitude       | number                 | No  | Latitude of the source.                                            |
21    | originLongitude      | number                 | No  | Longitude of the source.                                            |
22    | originPoiIds         | Record<number, string> | No  | List of POI IDs of the source. Currently, only POI IDs of Petal Maps and AutoNavi Map can be passed.|
23    | destinationName      | string                 | No  | Name of the destination.                                            |
24    | destinationLatitude  | number                 | Yes  | Latitude of the destination.                                            |
25    | destinationLongitude | number                 | Yes  | Longitude of the destination.                                            |
26    | destinationPoiIds    | Record<number, string> | No  | List of POI IDs of the destination. Currently, only POI IDs of Petal Maps and AutoNavi Map can be passed.|
27    | vehicleType          | number                 | No  | Transportation mode. The options are as follows: 0: driving; 1: walking; 2: cycling; 3: public transportation.|
28
29- Navigation scenarios
30
31    | Name              | Type                  | Mandatory| Description             |
32    | -------------------- | ---------------------- | ---- | ----------------- |
33    | sceneType            | number                 | Yes  | Intent scene, which indicates the purpose of the current request. Set it to **2** for navigation scenarios.|
34    | destinationName      | string                 | No  | Name of the destination.         |
35    | destinationLatitude  | number                 | Yes  | Latitude of the destination.         |
36    | destinationLongitude | number                 | Yes  | Longitude of the destination.         |
37    | destinationPoiIds    | Record<number, string> | No  | List of POI IDs of the destination. Currently, only POI IDs of Petal Maps and AutoNavi Map can be passed.|
38
39- Place search scenarios
40
41    | Name         | Type  | Mandatory| Description                 |
42    | --------------- | ------ | ---- | --------------------- |
43    | sceneType       | number | Yes  | Intent scene, which indicates the purpose of the current request. Set it to **3** for place search scenarios.|
44    | destinationName | string | Yes  | Name of the destination.             |
45
46
47## Developing a Caller Application
48
491. Import the module.
50    ```ts
51    import { common } from '@kit.AbilityKit';
52    ```
532. Construct parameters and call the **startAbilityByType** API.
54
55   You need to obtain the POI IDs of the destination and origin from each map system and pass the parameters **destinationPoiIds** and **originPoiIds** based on the mappings.
56
57
58    ```ts
59    let context = getContext(this) as common.UIAbilityContext;
60    let wantParam: Record<string, Object> = {
61      'sceneType': 1,
62      'destinationLatitude': 32.060844,
63      'destinationLongitude': 118.78315,
64      'destinationName': 'No.xx, xx Road, xx City',
65      'destinationPoiIds': {
66          1:'1111', // Key 1 indicates Petal Maps, and the value must be a POI in Petal Maps.
67          2:'2222' // Key 2 indicates AutoNavi Map, and the value must be a POI in AutoNavi Map.
68      } as Record<number, string>,
69      'originName': 'xx Park in xx City',
70      'originLatitude': 31.060844,
71      'originLongitude': 120.78315,
72      'originPoiIds': {
73          1: '3333',  // Key 1 indicates Petal Maps, and the value must be a POI in Petal Maps.
74          2: '4444'   // Key 2 indicates AutoNavi Map, and the value must be a POI in AutoNavi Map.
75      } as Record<number, string>,
76      'vehicleType': 0
77    };
78    let abilityStartCallback: common.AbilityStartCallback = {
79      onError: (code: number, name: string, message: string) => {
80        console.log(`onError code ${code} name: ${name} message: ${message}`);
81      },
82      onResult: (result)=>{
83        console.log(`onResult result: ${JSON.stringify(result)}`);
84      }
85    }
86
87    context.startAbilityByType("navigation", wantParam, abilityStartCallback,
88        (err) => {
89            if (err) {
90                console.error(`startAbilityByType fail, err: ${JSON.stringify(err)}`);
91            } else {
92                console.log(`success`);
93            }
94    });
95    ```
96
97**Effect**
98
99![Effect example](./figures/start-navigation-panel.png)
100
101## Developing a Target Application
102
1031. Configure [uris](../quick-start/module-configuration-file.md#skills) in the **module.json5** file.
104    1. Set the **linkFeature** field to declare the features supported by the application so that the system can match the application against all the installed applications on the device. The options are as follows:
105        | Value          | Description                        |
106        | -------------- | ---------------------------- |
107        | Navigation     | The application supports navigation.		|
108        | RoutePlan      | The application supports route planning.	|
109        | PlaceSearch    | The application supports place search.    |
110    2. Set **scheme**, **host**, **port**, and **path** or **pathStartWith** to match the URIs in Want to distinguish different features.
111    ```json
112    {
113      "abilities": [
114          {
115          "skills": [
116              {
117              "uris": [
118                  {
119                  "scheme": "maps", // It is for reference only. Ensure that the declared URI can be started by external systems.
120                  "host": "navigation",
121                  "path": "",
122                  "linkFeature": "Navigation" // Declare that the application supports navigation.
123                  },
124                  {
125                  "scheme": "maps", // It is for reference only. Ensure that the declared URI can be started by external systems.
126                  "host": "routePlan",
127                  "path": "",
128                  "linkFeature": "RoutePlan" // Declare that the application supports route planning.
129                  },
130                  {
131                  "scheme": "maps", // It is for reference only. Ensure that the declared URI can be started by external systems.
132                  "host": "search",
133                  "path": "",
134                  "linkFeature": "PlaceSearch" // Declare that the application supports place search.
135                  }
136              ]
137              }
138          ]
139          }
140      ]
141    }
142    ```
143
1442. Parse parameters and perform corresponding processing.
145
146    ```ts
147    UIAbility.onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void
148    ```
149
150    The **want.uri** parameter carries the URI corresponding to **linkFeature** configured by the target application.
151
152    **want.parameters** carries the parameters passed by the caller, which vary in different scenarios.
153
154    - Route planning scenarios
155
156        | Name              | Type  | Mandatory| Description                                                |
157        | -------------------- | ------ | ---- | ---------------------------------------------------- |
158        | originName           | string | No  | Name of the source.                                            |
159        | originLatitude       | number | No  | Latitude of the source.                                            |
160        | originLongitude      | number | No  | Longitude of the source.                                            |
161        | originPoiId          | string | No  | POI ID of the source. Currently, this parameter can be obtained only from Petal Maps and AutoNavi Map.     |
162        | destinationName      | string | No  | Name of the destination.                                            |
163        | destinationLatitude  | number | Yes  | Latitude of the destination.                                            |
164        | destinationLongitude | number | Yes  | Longitude of the destination.                                            |
165        | destinationPoiId     | string | No  | POI ID of the destination. Currently, this parameter can be obtained only from Petal Maps and AutoNavi Map.     |
166        | vehicleType          | number | No  | Transportation mode. The options are as follows: 0: driving; 1: walking; 2: cycling; 3: public transportation.|
167
168    - Navigation scenarios
169
170        | Name              | Type  | Mandatory| Description      |
171        | -------------------- | ------ | ---- | ---------- |
172        | destinationName      | string | No  | Name of the destination.  |
173        | destinationLatitude  | number | Yes  | Latitude of the destination.  |
174        | destinationLongitude | number | Yes  | Longitude of the destination.  |
175        | destinationPoiId     | string | No  | POI ID of the destination. Currently, this parameter can be obtained only from Petal Maps and AutoNavi Map.|
176
177    - Place search scenarios
178
179        | Name         | Type  | Mandatory| Description    |
180        | --------------- | ------ | ---- | -------- |
181        | destinationName | string | Yes  | Name of the destination.|
182
183The application can develop different style pages based on the features defined in [linkFeature](../quick-start/module-configuration-file.md#skills), such as route planning, navigation, and place search, as well as the received URI and parameters.
184
185**Sample Code**
186
187```ts
188import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
189import { hilog } from '@kit.PerformanceAnalysisKit';
190import { window } from '@kit.ArkUI';
191
192const TAG = 'EntryAbility'
193
194export default class EntryAbility extends UIAbility {
195    windowStage: window.WindowStage | null = null;
196
197    uri?: string;
198    destinationLatitude?: number;
199    destinationLongitude?: number;
200    destinationName?: string;
201    originName?: string;
202    originLatitude?: number;
203    originLongitude?: number;
204    vehicleType?: number;
205    destinationPoiId?: string;
206    originPoiId?: string;
207
208    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
209        hilog.info(0x0000, TAG, `onCreate, want=${JSON.stringify(want)}`);
210        super.onCreate(want, launchParam);
211        this.parseWant(want);
212    }
213
214    onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
215        hilog.info(0x0000, TAG, `onNewWant, want=${JSON.stringify(want)}`);
216        super.onNewWant(want, launchParam);
217        this.parseWant(want);
218        if (!this.windowStage) {
219            hilog.error(0x0000, TAG, 'windowStage is null');
220            this.context.terminateSelf();
221            return;
222        }
223        this.loadPage(this.windowStage);
224    }
225
226    private parseWant(want: Want): void {
227        this.uri = want.uri as string | undefined;
228        this.destinationLatitude = want.parameters?.destinationLatitude as number | undefined;
229        this.destinationLongitude = want.parameters?.destinationLongitude as number | undefined;
230        this.destinationName = want.parameters?.destinationName as string | undefined;
231        this.originName = want.parameters?.originName as string | undefined;
232        this.originLatitude = want.parameters?.originLatitude as number | undefined;
233        this.originLongitude = want.parameters?.originLongitude as number | undefined;
234        this.vehicleType = want.parameters?.vehicleType as number | undefined;
235        this.destinationPoiId = want.parameters?.destinationPoiId as string | undefined;
236        this.originPoiId = want.parameters?.originPoiId as string | undefined;
237    }
238
239    private loadPage(windowStage: window.WindowStage): void {
240        hilog.info(0x0000, TAG, `loadPage, uri=${this.uri}`);
241        if (this.uri === 'maps://navigation') {
242            // Construct parameters for the navigation scenario.
243            const storage: LocalStorage = new LocalStorage({
244                "destinationLatitude": this.destinationLatitude,
245                "destinationLongitude": this.destinationLongitude,
246                "destinationPoiId": this.destinationPoiId
247            } as Record<string, Object>);
248            // Open the navigation page.
249            windowStage.loadContent('pages/NavigationPage', storage)
250        } else if (this.uri === 'maps://routePlan') {
251            // Construct parameters for the path planning scenario.
252            const storage: LocalStorage = new LocalStorage({
253                "destinationLatitude": this.destinationLatitude,
254                "destinationLongitude": this.destinationLongitude,
255                "destinationName": this.destinationName,
256                "originName": this.originName,
257                "originLatitude": this.originLatitude,
258                "originLongitude": this.originLongitude,
259                "vehicleType": this.vehicleType,
260                "destinationPoiId": this.destinationPoiId,
261                "originPoiId": this.originPoiId
262            } as Record<string, Object>);
263            // Open the route planning page.
264            windowStage.loadContent('pages/RoutePlanPage', storage)
265        }  else if (this.uri === 'maps://search') {
266            // Construct parameters for the place search scenario.
267            const storage: LocalStorage = new LocalStorage({
268                "destinationName": this.destinationName
269            } as Record<string, Object>);
270            // Open the place search page.
271            windowStage.loadContent('pages/PlaceSearchPage', storage)
272        } else {
273            // Display the home page by default.
274            windowStage.loadContent('pages/Index', (err) => {
275                if (err.code) {
276                    hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s',
277                        JSON.stringify(err) ?? '');
278                    return;
279                }
280                hilog.info(0x0000, TAG, 'Succeeded in loading the content.');
281            });
282        }
283    }
284
285    onDestroy(): void {
286        hilog.info(0x0000, TAG, `onDestroy`);
287    }
288
289    onWindowStageCreate(windowStage: window.WindowStage): void {
290        hilog.info(0x0000, TAG, `onWindowStageCreate`);
291        this.windowStage = windowStage;
292        this.loadPage(this.windowStage);
293    }
294
295    onWindowStageDestroy(): void {
296        hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy');
297    }
298
299    onForeground(): void {
300        hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground');
301    }
302
303    onBackground(): void {
304        hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground');
305    }
306}
307```
308