Docs
Inputs

Location Picker

A map picker with a red pin that lifts while the map moves and drops into place, looking up the address under it on a glass card.

$npx swiftpieces add LocationPicker
See it in a Pro app On a real screen in one of the Pro apps: open it with Pro, take it apart, remix it, and copy the SwiftUI.
Free · MIT + Commons ClauseiOS 17.0+Liquid Glasslocationmappinmapkitgeocodingdeliveryaddresscorelocation
Type
LocationPicker
Files
LocationPicker.swift
Depends on
Nothing (Apple frameworks only)
Version
1.2.0
  • Info.plist NSLocationWhenInUseUsageDescription: Shows where you are so you can pick a spot on the map.
In a full screen · SwiftPieces ProNearbyA map of places nearby with a Maps-style sheet that scrolls, snaps and hands off to its list.

A map you drag under a fixed pin to choose an exact spot, with the address of wherever the pin lands. The pin stays in the middle of the visible map. While the map moves it lifts and its shadow spreads; when the map settles it drops and presses into place, selection is set to the coordinate, and the address is looked up after a short pause. A newer settle cancels the lookup in flight, so an address never lands on the wrong spot, and recent answers are cached by position (about 5 m), so nudging back costs no request. Location permission is only requested when the locate button is tapped. swift @State private var place: LocationPicker.Place? LocationPicker(selection: $place, initialCenter: store.coordinate) { place in order.dropOff = place }

Notes

  • The picker takes the size it is given, at least 320 pt tall: full screen, in a sheet, or .frame(height: 340).clipShape(.rect(cornerRadius: 26)) inside a form. Bind selection, and pass onConfirm for the Confirm button. Add NSLocationWhenInUseUsageDescription to your Info.plist for the locate button. Full screen, the map already runs under the status bar and the home indicator while the card and the locate button stay clear of them, so leave out .ignoresSafeArea(), which would push both under the system bars.
  • The pin stays in the middle of the map the card leaves visible. While the map moves it lifts 12 pt, its shadow spreads and a small mark stays on the exact spot. Picked up by your drag, it springs about a point past its lift and settles; a flight (locate, a VoiceOver move, a new selection) lifts it on a short spring. When the map settles it drops on a spring that never overshoots, so the tip stops on the spot instead of sinking through it, then gives a little from the tip as it meets the ground and springs back into shape, with a light tap on that beat. Only a real change of the spot under the pin lifts it, so the camera reports MapKit sends on appear, on rotation and on resize do nothing.
  • selection is set when the pin settles (coordinate only) and again when the address arrives. Its coordinate is always where the pin points; the address is the nearest one found. Setting selection from outside, a search result or a saved place, moves the map there, and a place that already has an address is shown without a lookup.
  • The address is looked up 300 ms after the map settles. A new settle, or leaving the screen, cancels the lookup in flight and its request, and an answer for a spot that is no longer under the pin is dropped. Answers are cached per picker by position rounded to about 5 m (the 40 most recent), so nudging back to a known spot sends nothing, which also keeps clear of the geocoder's rate limit.
  • iOS 26 uses MKReverseGeocodingRequest, reading the street and postal code from the map item's placemark (dynamically, as Address Field does) with MKAddressRepresentations as the fallback. iOS 17 to 25 uses CLGeocoder, kept in a deprecated function that only runs below iOS 26, so the file builds without warnings on both.
  • The card is a floating liquid glass panel. It has one state per moment: the last address (or "Dropped pin" until one has been found) dimmed with "Locating…" from the moment the map moves until the next address arrives (the "Locating…" line breathes once the pin is down), loading lines only for the first lookup and for Retry, street and locality once found, "Dropped pin" with the coordinates where there is no address (open water), and "Couldn't find the address" with the coordinates when the lookup fails (offline, throttled). Every state keeps the same two lines, and the readout changes once per move: each line morphs letter by letter as the address arrives, so letters the old and new lines share hold still and a nudge along a street moves only the house number (a line too long to fit shrinks to fit and blurs across instead). The card keeps its tallest size and the map's center only moves when it grows, so nothing jumps as the text changes.
  • When the lookup fails, a glass Retry bubble pinches off the card's trailing end: the card gives up that width and Retry springs out of its end, joined to it by a liquid neck. It melts back into the card when tapped or when the map moves.
  • Confirm is a red glass capsule resting apart below the card. It buds down out of the card once the spot under the pin has its answer (its address, no address, or a failed lookup), born inside the card and pulling a liquid neck that thins and snaps as it springs to its place, and melts back up into the card on a spring with no bounce, its red draining as it goes, the moment the map moves. Its place keeps its height while it is away, so the card and the map's center never move. A Retry keeps it out; tapped while that lookup runs, it spins and waits for the address (up to four seconds), then hands over the place; after a failed lookup it hands over the coordinate alone. Return confirms with a hardware keyboard. Leave out onConfirm to hide it and read selection yourself.
  • The locate button asks for When In Use permission on its first tap, never on appear. It spins while finding you, flies the camera to you, and fills in once the pin sits on you; a fix from the last minute is used at once. When your location can't be found it shakes once, on the beat of the error haptic. Camera flights take longer the farther they go: about 0.55 s for a VoiceOver nudge or zoom, up to 1.2 s across town. With approximate location the map shows the area the fix covers instead of a street. When access is denied the arrow is slashed and a tap explains and offers Settings; when it is restricted a tap explains. Dragging works the same without permission.
  • Where the map starts: the place in selection, else initialCenter, else the person's location when the app already has permission, else central Lisbon.
  • MapKit's logo and legal notice stay visible above the card: the card and Confirm's place inset the map's safe area, which is also where MapKit puts the camera's center.
  • VoiceOver: the address readout is one element, "Selected location", with the address, "Dropped pin" and the coordinates, "Locating" or "Finding the address" as its value. Its actions move the map a quarter of the visible span north, south, east or west, zoom in and out, use your location and retry. After the map settles from a move the new address is announced. The pin is decorative and hidden; the locate button reads its state.
  • Haptics: a light tap as the pin meets the ground (at once if the map moves again before it lands, so every settle gets one), success when Confirm hands over the place, a selection tick on Retry, and an error when Retry or locating fails. Nothing while panning, and nothing for a lookup that fails on its own.
  • Dynamic Type: the card's text grows and wraps up to accessibility sizes (where it no longer morphs), Retry stays joined to the card's end, Confirm stays full width, and the locate button grows up to 64 pt. Right to left, the card mirrors and the locate button sits top left; the map is never mirrored.
  • Motion: Retry, Confirm and the locate button sink a couple of points under the finger and spring back with a little bounce, and the locate arrow blurs into its filled form, as the spinner and Confirm's label do into each other. The card changes its text in place without moving, and the map's own panning and zooming stay MapKit's. The pin and the map are content and stay as they are; only the chrome over them is glass.
  • Reduce Motion: the pin dims instead of lifting and lands without the press, its tap playing as the map settles; the camera jumps instead of flying; Confirm and Retry fade in and out where they rest instead of budding, and the readout cross-fades instead of morphing; the loading lines and "Locating…" still breathe in opacity, so a lookup never looks frozen; buttons shift brightness instead of dipping when pressed; and a failed locate blinks the glyph instead of shaking. Haptics and announcements are unchanged. Reduce Transparency draws the glass solid.
  • The map pans and zooms but doesn't rotate or tilt, so north stays up. A drag that starts on the map pans it, inside a ScrollView or a Form too; in a sheet, the grabber still dismisses.
  • Style sets the glass tint of the card, Retry and the locate button (surface, neutral glass by default), label, secondary label, the loading bars (field), the pin and its ink, Confirm's tint and its ink, the card's corner radius, points of interest (off by default, so the streets and the pin read first) and the muted map (on by default). Messages replaces any line, for example confirm: "Deliver here". Geocoder swaps MapKit for your own backend, or a fixed answer for previews and tests.

Usage

LocationPickerExample()

Parameters

ParameterDescription
selectionThe picked place. Set when the pin settles (coordinate only) and again when its address arrives. Setting it from outside moves the map there; a place that already has an address is shown without a lookup.
initialCenterWhere the map starts when selection is nil. nil starts at the person's location when the app already has permission, otherwise in central Lisbon.
spanHow much map shows around the pin at first, in meters across. Defaults to 500, street level.
showsLocationButtonShows the locate button in the top trailing corner. It asks for When In Use permission on its first tap, never before.
geocoderWhere addresses come from. .mapKit (the default) uses MKReverseGeocodingRequest on iOS 26 and the system geocoder before it. Pass your own for a backend, previews or tests.
messagesThe card's copy. Defaults are localizable through your String Catalog; replace any line, for example confirm with "Deliver here".
styleColors, the card's corner radius and the map's look. Defaults to the SwiftPieces house palette, adapting to light and dark, with the red pin and Confirm.
onConfirmCalled with the place when Confirm is tapped. Tapped while the address is still on its way, Confirm waits for it (up to four seconds) and then hands over what it has. nil hides the button, for pickers inside your own form.

Install

Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.

Terminal

$npx swiftpieces add LocationPicker

Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected

>Add the SwiftPieces "Location Picker" piece to my app

Or copy the source above into your app.

New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first

Building a whole app? See SwiftPieces Pro →

All inputs and forms →

Build it yourself: SwiftUI haptics guide

On this page

SwiftPiecesPro

Build the whole app with one library.

Production-ready screens, whole flows, complete app templates, a Build Kit your agent follows and Pro remixing.

Explore Pro