One Logo Pool Ball
_CoreLocationUI_SwiftUI · IOS API REFERENCE

LocationButton

struct · iOS 15.0+ · SDK 27.1

@MainActor @preconcurrency struct LocationButton

A SwiftUI button that grants one-time location authorization. `LocationButton` simplifies requesting one-time authorization to access location data. Add this button to your SwiftUI user interface in situations when users may want to grant temporary access to their location data each time they use a particular feature of your app. ![Screenshot of the location button with an icon that uses the filled arrow style and a label that shows Current Location.](locationbutton-1) The first time a user taps this button, <doc://com.apple.documentation/documentation/corelocation> asks the user to confirm that they’re comfortable using this UI element when they want to grant temporary access to their location data. If the user agrees, the app receives temporary <doc://com.apple.documentation/documentation/corelocation/clauthorizationstatus/authorizedwheninuse> authorization, like when the user chooses _Allow Once_ in response to your app’s standard location authorization request. This temporary authorization expires when your app is no longer in use. After the user agrees to using `LocationButton`, the button becomes approved to request future authorizations without displaying an additional alert to the user. The next time the user taps it, this button simply grants one-time authorization without requiring confirmation. After you receive this temporary authorization, fetch the user’s location using the <doc://com.apple.documentation/documentation/corelocation> API and perform any app-specific tasks related to that location data. Connect the button to initiate the tasks you want to perform after getting authorization by specifying an action when you create the button. Keep in mind that this action activates every time the user taps this button, regardless of whether the app already has location authorization. Create a `LocationButton` in SwiftUI like this: ```swift LocationButton(.currentLocation) { // Fetch location with Core Location. } .symbolVariant(.fill) .labelStyle(.titleAndIcon) ``` > Important: When a user taps the button, it only provides one-time authorization to fetch location data — not the location data itself. For more details about fetching location data, see <doc://com.apple.documentation/documentation/corelocation/configuring_your_app_to_use_location_services>. Configure the button to display an icon, a label, or both using the <doc://com.apple.documentation/documentation/swiftui/view/labelstyle(_:)> view modifier. If you include an icon, you can customize its appearance using the <doc://com.apple.documentation/documentation/swiftui/view/symbolvariant(_:)> modifier. For design guidance, see [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/ios/app-architecture/accessing-user-data/).

Members (1)

init · iOS 15.0+

init

TypeScript
static init(title: (LocationButton_Title) | null, action: (() => void)): Promise<LocationButton>
Swift declaration
nonisolated init(_ title: LocationButton.Title? = .currentLocation, action: @escaping () -> Void)

Creates a location button with the specified title and action. - Parameter title: The text that the button displays. For possible values, see ``CoreLocationUI/LocationButton/Title``. - Parameter action: The action that initiates every time the user taps the button.

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

LocationButton.body

This protocol needs associated types that cannot yet cross the bridge.

All _CoreLocationUI_SwiftUI types →