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