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. 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. 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. 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 **ohos.app.ability.common** 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 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 112 ```json 113 { 114 "abilities": [ 115 { 116 "skills": [ 117 { 118 "uris": [ 119 { 120 "scheme": "maps", // It is for reference only. Ensure that the declared URI can be started by external systems. 121 "host": "navigation", 122 "path": "", 123 "linkFeature": "Navigation" // Declare that the application supports navigation. 124 }, 125 { 126 "scheme": "maps", // It is for reference only. Ensure that the declared URI can be started by external systems. 127 "host": "routePlan", 128 "path": "", 129 "linkFeature": "RoutePlan" // Declare that the application supports route planning. 130 }, 131 { 132 "scheme": "maps", // It is for reference only. Ensure that the declared URI can be started by external systems. 133 "host": "search", 134 "path": "", 135 "linkFeature": "PlaceSearch" // Declare that the application supports place search. 136 } 137 ] 138 } 139 ] 140 } 141 ] 142 } 143 ``` 144 1452. Parse parameters and perform corresponding processing. 146 147 ```ts 148 UIAbility::onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void 149 ``` 150 151 The **want.uri** parameter carries the URI corresponding to **linkFeature** configured by the target application. 152 153 **want.parameters** carries the parameters passed by the caller, which vary in different scenarios. 154 155 - Route planning scenarios 156 157 | Name | Type | Mandatory| Description | 158 | -------------------- | ------ | ---- | ---------------------------------------------------- | 159 | originName | string | No | Name of the source. | 160 | originLatitude | number | No | Latitude of the source. | 161 | originLongitude | number | No | Longitude of the source. | 162 | originPoiId | string | No | POI ID of the source. Currently, this parameter can be obtained only from Petal Maps and AutoNavi Map. | 163 | destinationName | string | No | Name of the destination. | 164 | destinationLatitude | number | Yes | Latitude of the destination. | 165 | destinationLongitude | number | Yes | Longitude of the destination. | 166 | destinationPoiId | string | No | POI ID of the destination. Currently, this parameter can be obtained only from Petal Maps and AutoNavi Map. | 167 | vehicleType | number | No | Transportation mode. The options are as follows: 0: driving; 1: walking; 2: cycling; 3: public transportation.| 168 169 - Navigation scenarios 170 171 | Name | Type | Mandatory| Description | 172 | -------------------- | ------ | ---- | ---------- | 173 | destinationName | string | No | Name of the destination. | 174 | destinationLatitude | number | Yes | Latitude of the destination. | 175 | destinationLongitude | number | Yes | Longitude of the destination. | 176 | destinationPoiId | string | No | POI ID of the destination. Currently, this parameter can be obtained only from Petal Maps and AutoNavi Map.| 177 178 - Place search scenarios 179 180 | Name | Type | Mandatory| Description | 181 | --------------- | ------ | ---- | -------- | 182 | destinationName | string | Yes | Name of the destination.| 183 184 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 and parameters. 185 186**Sample Code** 187 188```ts 189import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; 190import { hilog } from '@kit.PerformanceAnalysisKit'; 191import { window } from '@kit.ArkUI'; 192 193const TAG = 'EntryAbility' 194 195export default class EntryAbility extends UIAbility { 196 windowStage: window.WindowStage | null = null; 197 198 uri?: string; 199 destinationLatitude?: number; 200 destinationLongitude?: number; 201 destinationName?: string; 202 originName?: string; 203 originLatitude?: number; 204 originLongitude?: number; 205 vehicleType?: number; 206 destinationPoiId?: string; 207 originPoiId?: string; 208 209 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 210 hilog.info(0x0000, TAG, `onCreate, want=${JSON.stringify(want)}`); 211 super.onCreate(want, launchParam); 212 this.parseWant(want); 213 } 214 215 onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { 216 hilog.info(0x0000, TAG, `onNewWant, want=${JSON.stringify(want)}`); 217 super.onNewWant(want, launchParam); 218 this.parseWant(want); 219 if (!this.windowStage) { 220 hilog.error(0x0000, TAG, 'windowStage is null'); 221 this.context.terminateSelf(); 222 return; 223 } 224 this.loadPage(this.windowStage); 225 } 226 227 private parseWant(want: Want): void { 228 this.uri = want.uri as string | undefined; 229 this.destinationLatitude = want.parameters?.destinationLatitude as number | undefined; 230 this.destinationLongitude = want.parameters?.destinationLongitude as number | undefined; 231 this.destinationName = want.parameters?.destinationName as string | undefined; 232 this.originName = want.parameters?.originName as string | undefined; 233 this.originLatitude = want.parameters?.originLatitude as number | undefined; 234 this.originLongitude = want.parameters?.originLongitude as number | undefined; 235 this.vehicleType = want.parameters?.vehicleType as number | undefined; 236 this.destinationPoiId = want.parameters?.destinationPoiId as string | undefined; 237 this.originPoiId = want.parameters?.originPoiId as string | undefined; 238 } 239 240 private loadPage(windowStage: window.WindowStage): void { 241 hilog.info(0x0000, TAG, `loadPage, uri=${this.uri}`); 242 if (this.uri === 'maps://navigation') { 243 // Construct parameters for the navigation scenario. 244 const storage: LocalStorage = new LocalStorage({ 245 "destinationLatitude": this.destinationLatitude, 246 "destinationLongitude": this.destinationLongitude, 247 "destinationPoiId": this.destinationPoiId 248 } as Record<string, Object>); 249 // Open the navigation page. 250 windowStage.loadContent('pages/NavigationPage', storage) 251 } else if (this.uri === 'maps://routePlan') { 252 // Construct parameters for the path planning scenario. 253 const storage: LocalStorage = new LocalStorage({ 254 "destinationLatitude": this.destinationLatitude, 255 "destinationLongitude": this.destinationLongitude, 256 "destinationName": this.destinationName, 257 "originName": this.originName, 258 "originLatitude": this.originLatitude, 259 "originLongitude": this.originLongitude, 260 "vehicleType": this.vehicleType, 261 "destinationPoiId": this.destinationPoiId, 262 "originPoiId": this.originPoiId 263 } as Record<string, Object>); 264 // Open the route planning page. 265 windowStage.loadContent('pages/RoutePlanPage', storage) 266 } else if (this.uri === 'maps://search') { 267 // Construct parameters for the place search scenario. 268 const storage: LocalStorage = new LocalStorage({ 269 "destinationName": this.destinationName 270 } as Record<string, Object>); 271 // Open the place search page. 272 windowStage.loadContent('pages/PlaceSearchPage', storage) 273 } else { 274 // Display the home page by default. 275 windowStage.loadContent('pages/Index', (err) => { 276 if (err.code) { 277 hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s', 278 JSON.stringify(err) ?? ''); 279 return; 280 } 281 hilog.info(0x0000, TAG, 'Succeeded in loading the content.'); 282 }); 283 } 284 } 285 286 onDestroy(): void { 287 hilog.info(0x0000, TAG, `onDestroy`); 288 } 289 290 onWindowStageCreate(windowStage: window.WindowStage): void { 291 hilog.info(0x0000, TAG, `onWindowStageCreate`); 292 this.windowStage = windowStage; 293 this.loadPage(this.windowStage); 294 } 295 296 onWindowStageDestroy(): void { 297 hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy'); 298 } 299 300 onForeground(): void { 301 hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground'); 302 } 303 304 onBackground(): void { 305 hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); 306 } 307} 308``` 309