1# LocationButton 2 3The **\<LocationButton>** security component allows you to obtain temporary precise location permission from the user by their touching the button, eliminating the need for a permission request dialog box. 4 5> **NOTE** 6> 7> This component is supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version. 8 9## Child Components 10 11Not supported 12 13## APIs 14 15### LocationButton 16 17LocationButton() 18 19Creates a Location button with an icon, text, and background. 20 21You may want to learn the [restrictions on security component styles](../../../security/AccessToken/security-component-overview.md#constraints) to avoid authorization failures caused by incompliant styles. 22 23**Atomic service API**: This API can be used in atomic services since API version 11. 24 25**System capability**: SystemCapability.ArkUI.ArkUI.Full 26 27### LocationButton 28 29LocationButton(option:LocationButtonOptions) 30 31Creates a Location button that contains the specified elements. 32 33You may want to learn the [restrictions on security component styles](../../../security/AccessToken/security-component-overview.md#constraints) to avoid authorization failures caused by incompliant styles. 34 35**Atomic service API**: This API can be used in atomic services since API version 11. 36 37**System capability**: SystemCapability.ArkUI.ArkUI.Full 38 39**Parameters** 40 41| Name| Type| Mandatory| Description| 42| -------- | -------- | -------- | -------- | 43| option | [LocationButtonOptions](#locationbuttonoptions) | No| Creates a Location button that contains the specified elements.| 44 45## LocationButtonOptions 46 47**Atomic service API**: This API can be used in atomic services since API version 11. 48 49**System capability**: SystemCapability.ArkUI.ArkUI.Full 50 51| Name| Type| Mandatory| Description| 52| -------- | -------- | -------- | -------- | 53| icon | [LocationIconStyle](#locationiconstyle) | No| Icon style of the Location button.<br>If this parameter is not specified, no icon is contained. Either **icon** or **text**, or both, must be set.| 54| text | [LocationDescription](#locationdescription) | No| Text on the Location button.<br>If this parameter is not specified, no text is contained. Either **icon** or **text**, or both, must be set.| 55| buttonType | [ButtonType](ts-basic-components-button.md#buttontype) | No| Background type of the Location button.<br>If this parameter is not specified, the system uses a capsule-type button. | 56 57## LocationIconStyle 58 59**Atomic service API**: This API can be used in atomic services since API version 11. 60 61**System capability**: SystemCapability.ArkUI.ArkUI.Full 62 63| Name| Value| Description| 64| -------- | -------- | -------- | 65| FULL_FILLED | 0 | Filled style icon.| 66| LINES | 1 | Line style icon.| 67 68## LocationDescription 69 70**Atomic service API**: This API can be used in atomic services since API version 11. 71 72**System capability**: SystemCapability.ArkUI.ArkUI.Full 73 74| Name| Value| Description| 75| -------- | -------- | -------- | 76| CURRENT_LOCATION | 0 | The text on the Location button is **Current location**.| 77| ADD_LOCATION | 1 | The text on the Location button is **Add location**.| 78| SELECT_LOCATION | 2 | The text on the Location button is **Select location**.| 79| SHARE_LOCATION | 3 | The text on the Location button is **Share location**.| 80| SEND_LOCATION | 4 | The text on the Location button is **Send location**.| 81| LOCATING | 5 | The text on the Location button is **Locate**.| 82| LOCATION | 6 | The text on the Location button is **Location**.| 83| SEND_CURRENT_LOCATION | 7 | The text on the Location button is **Send current location**.| 84| RELOCATION | 8 | The text on the Location button is **Relocate**.| 85| PUNCH_IN | 9 | The text on the Location button is **Punch in**.| 86| CURRENT_POSITION | 10 | The text on the Location button is **Current position**.| 87 88## LocationButtonOnClickResult 89 90**Atomic service API**: This API can be used in atomic services since API version 11. 91 92**System capability**: SystemCapability.ArkUI.ArkUI.Full 93 94| Name| Value| Description| 95| -------- | -------- | -------- | 96| SUCCESS | 0 | The Location button is touched successfully.| 97| TEMPORARY_AUTHORIZATION_FAILED | 1 | Temporary authorization fails after the Location button is touched.| 98 99## Attributes 100 101This component can only inherit the [universal attributes of security components](ts-securitycomponent-attributes.md#attributes) 102 103## Events 104 105Only the following events are supported. 106 107### onClick 108 109onClick(event: (event: ClickEvent, result: LocationButtonOnClickResult) => void) 110 111Called when a click event occurs. 112 113**Atomic service API**: This API can be used in atomic services since API version 11. 114 115**System capability**: SystemCapability.ArkUI.ArkUI.Full 116 117**Parameters** 118 119| Name| Type | Mandatory| Description | 120|------------|------|-------|---------| 121| event | [ClickEvent](ts-universal-events-click.md#clickevent) |Yes|See **ClickEvent**.| 122| result | [LocationButtonOnClickResult](#locationbuttononclickresult)| Yes| Authorization result.| 123 124## Example 125 126```ts 127// xxx.ets 128@Entry 129@Component 130struct Index { 131 build() { 132 Row() { 133 Column({space:10}) { 134 // Create a default Location button with an icon, text, and background. 135 LocationButton().onClick((event: ClickEvent, result: LocationButtonOnClickResult)=>{ 136 console.info("result " + result) 137 }) 138 // Whether an element is contained depends on whether the parameter corresponding to the element is specified. If buttonType is not passed in, the button uses the ButtonType.Capsule settings. 139 LocationButton({icon:LocationIconStyle.LINES}) 140 // Create a button with only an icon and background. If the alpha value of the most significant eight bits of the background color is less than 0x1A, the system forcibly adjusts the alpha value to 0xFF. 141 LocationButton({icon:LocationIconStyle.LINES, buttonType:ButtonType.Capsule}) 142 .backgroundColor(0x10007dff) 143 // Create a button with an icon, text, and background. If the alpha value of the most significant eight bits of the background color is less than 0x1A, the system forcibly adjusts the alpha value to 0xFF. 144 LocationButton({icon:LocationIconStyle.LINES, text:LocationDescription.CURRENT_LOCATION, buttonType:ButtonType.Capsule}) 145 }.width('100%') 146 }.height('100%') 147 } 148} 149``` 150 151 152