SP GlassKit1.1.0

GlassLocationButton

Location action with injected state; permission is requested by the host application only.

  • Custom glass
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-location-button

Draws its own Liquid Glass surface, with an opaque form when Reduce Transparency is on.

GlassLocationButton running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-location-button

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-location-button
ModuleSPGlassMaps
Kindcustom-glass — a round interactive glassSurface
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Maps/GlassLocationButtonExample.swift

Minimal usage

Swift
GlassLocationButton(state: model.locationState) { model.locationButtonTapped() }

Variants

StateSymbolLabelEnabled
.idlelocation"Show my location"yes
.locatinglocation, pulsing, with an arc on the rim"Finding your location"yes
.followinglocation.fill, primary colour"Following your location"yes
.deniedlocation.slash with an exclamation badge"Location access denied"yes — the host can explain or open Settings
.unavailablelocation.slash, dimmed"Location unavailable"no

Parameters

ParameterTypeDefaultMeaning
stateGlassLocationState—State reported by the host.
hintString?nilExplanation read as the accessibility hint and shown as the tooltip on macOS.
sizeGlassControlSize.regularSize of the control.
action@MainActor () -> Void—Called on activation.

The mapping from state to symbol, label and enabled flag is GlassLocationPresentation(state), a value type usable without the view.

States

See the table above. The pulse of .locating is a symbol effect that stops with Reduce Motion; the state is then conveyed by the label alone.

Advanced example

Swift
@MainActor @Observable
final class LocationModel: NSObject, CLLocationManagerDelegate {
    private let manager = CLLocationManager()
    private(set) var state = GlassLocationState.idle

    func buttonTapped() {
        switch manager.authorizationStatus {
        case .notDetermined: manager.requestWhenInUseAuthorization()   // the host asks, never the button
        case .denied: openSettings()
        case .restricted: state = .unavailable
        default: state = .locating; manager.startUpdatingLocation()
        }
    }
    // delegate callbacks update `state` to .following, .denied, …
}

GlassLocationButton(
    state: model.state,
    hint: model.state == .denied ? "Opens Settings to allow location access" : nil
) { model.buttonTapped() }

Accessibility

  • The label is the state itself ("Location access denied"), so VoiceOver announces it without relying on the symbol.
  • Denied and unavailable use a slashed symbol and their own label — never colour alone.
  • hint becomes the accessibility hint; while locating the button has the "updates frequently" trait.
  • The target is at least 44 points on iOS and iPadOS.

Limits

  • The button never requests the location permission, never reads a position and does not import Core Location: all of that is the host's code.
  • There is no visible text next to the symbol; put a banner or an alert in the host if the denied state needs a visible explanation.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassLocationButtonExample: GlassExample {
    public static let componentID = "glass-location-button"
    /// The example plays the host's role with a simulated state: no permission is requested, no position is read.
    @State private var state = GlassLocationState.idle
    @State private var message = "Sample data · simulated states, no location access"

    public init() {}

    public var body: some View {
        VStack(spacing: 16) {
            SampleMapBackdrop()
                .overlay(alignment: .bottomTrailing) {
                    GlassLocationButton(state: state, hint: hint) { advance() }
                        .padding()
                }
            Picker("Simulated state", selection: $state) {
                ForEach(GlassLocationState.allCases, id: \.self) { state in
                    Text(GlassLocationPresentation(state).label).tag(state)
                }
            }
            .padding(.horizontal)
            HStack(spacing: 12) {
                ForEach(GlassLocationState.allCases, id: \.self) { state in
                    GlassLocationButton(state: state, size: .small) {}
                }
            }
            Text(message)
                .font(.caption)
                .foregroundStyle(.secondary)
                .padding(.horizontal)
        }
        .padding(.bottom)
    }

    private var hint: String? {
        switch state {
        case .denied: "Location access was refused. Activating the button would open Settings in a real application."
        case .unavailable: "Location services are off on this device."
        default: nil
        }
    }

    /// What a host might do on a tap, simulated.
    private func advance() {
        switch state {
        case .idle:
            state = .locating
            message = "The host would start location updates here."
        case .locating:
            state = .following
            message = "A position arrived: the map follows it."
        case .following:
            state = .idle
            message = "Following stopped."
        case .denied:
            message = "The host would open Settings here."
        case .unavailable:
            break
        }
    }
}

#Preview("GlassLocationButton") { GlassLocationButtonExample().glassTheme(.emerald) }

Registry entry

Identifierglass-location-button
Version1.1.0
Depends onglass-foundation, glass-icon-button
FrameworksSwiftUI
Public symbolsGlassLocationState, GlassLocationPresentation, GlassLocationButton
LicenceMIT
Manifestmanifest.json

Files