A simple and lightweight Swift package which provides a SwiftUI view for interactive geo coordinates input!

Overview

LocationPicker for SwiftUI

LocationPicker for SwiftUI is a very simple and lightweight Swift package which provides you a SwiftUI view for interactive coordinates input!

First you need to create a view with a binding property of CLLocationCoordinate2D type (remember to import the MapKit framework!). This means that once the position is selected coordinates are directly passed to your previous view through the powerful binding system of SwiftUI without any additional effort. Now put the LocationPicker view into a Sheet or a NavigationLink passing the binding value previously mentioned.
The user is now free to navigate around the map and select the location. Once pressed anywhere on the map, an annotation will appear on the map while coordinates are always displayed in real time at the bottom of the screen. You can also provide a custom text to tell the user what to do.

Example

Here's a short usage example. You can find the full code in UsageExample.swift

@State private var coordinates = CLLocationCoordinate2D(latitude: 37.333747, longitude: -122.011448)
@State private var showSheet = false

var body: some View {
    Button("Select location") {
        self.showSheet.toggle()
    }

    .sheet(isPresented: $showSheet) {
        NavigationView {
            
            // Just put the view into a sheet or navigation link
            LocationPicker(instructions: "Tap somewhere to select your coordinates", coordinates: $coordinates)
                
            // You can assign it some NavigationView modifiers
                .navigationTitle("Location Picker")
                .navigationBarTitleDisplayMode(.inline)
                .navigationBarItems(leading: Button(action: {
                    self.showSheet.toggle()
                }, label: {
                    Text("Close").foregroundColor(.red)
                }))
        }
    }
}

Installation

Required:

  • iOS 14.0 or above
  • Xcode 12.0 or above

In Xcode go to File -> Swift Packages -> Add Package Dependency and paste in the repo's url: https://github.com/alessiorubicini/LocationPickerForSwiftUI. Then choose the main branch (versions support coming soon).

You might also like...
A library that provides undo semantics for the Composable Architecture with optional bridging tofUndoManager.

Swift Composable Undo A library that provides undo semantics for the Composable Architecture with optional bridging with UndoManager. Motivation It is

A swift package(SPM) with iOS UI component that loads and displays images from remote urls or local assets and displays in a slide-show form with auto scroll feature.

MDBannersView A swift package with an iOS UI component that loads and displays images from remote urls, local assets and displays in a slide-show form

An example to-do list app using SwiftUI which is introduced in WWDC19
An example to-do list app using SwiftUI which is introduced in WWDC19

SwiftUITodo SwiftUITodo is an example to-do list application using SwiftUI which is first introduced in WWDC19 keynote. Requirements Xcode 11 Beta Swi

Quotes App is quotes browsing app which is built with Quotable Free API completely in SwiftUI.
Quotes App is quotes browsing app which is built with Quotable Free API completely in SwiftUI.

Quotes App is quotes browsing app which is built with Quotable Free API completely in SwiftUI. You can watch the whole journey of building this

Your SwiftUI custom slider is crap. Here's mine, which is also crap, but it's my crap

Fuck your custom slider It doesn't work. Sure, it looks great, with gradients, and multiple thumbs, but really, it's useless. No more paying for a sub

A SwiftUI component which handles logging in with Apple to Firebase
A SwiftUI component which handles logging in with Apple to Firebase

Login with Apple Firebase SwiftUI I made this SwiftUI component to handle logging in with Apple to Firebase. Demo Gif Usage in SwiftUI struct ContentV

A simple confetti view for apps using SwiftUI.
A simple confetti view for apps using SwiftUI.

ConfettiView Create fun animated confetti views with ease! Installation Use Swift Package Manager to install this package: https://github.com/benlmyer

New version of CardinalKit based on the Swift Package Manager and a modularized architecture.

CardinalKit Open-source framework for rapid development of modern, interoperable digital health applications. Contributing Contributions to this proje

Releases(1.1.1)
Owner
Alessio Rubicini
Computer science student at University of Camerino and iOS developer 🇮🇹👨🏻‍💻
Alessio Rubicini
ViruSafe aims to help the fight with COVID-19 by offering people to share their symptoms as well track the spread of COVID-19 with an interactive map

ViruSafe aims to help the fight with COVID-19 by offering people to share their symptoms as well track the spread of COVID-19 with an interactive map, that shows how the infection has spread throughout Bulgaria.

scalefocus 16 Feb 9, 2022
A macOS auxiliary app to choose results from cloud input methods

CloudInputAssist Introduction 介绍 一个 macOS 辅助应用程序,用于使用云输入法(例如谷歌云输入法)API 提供辅助的候选词结果。 Motivation 动机 使用不联网的本地输入法时,长句的候选词往往不太理想,尤其是使用双拼输入时。这种情况下,借助一些输入法的云计

JJAYCHEN 1 Jan 3, 2023
A simple todo app which aims to demonstrate some new concepts from SwiftUI 3

TodoAppSwiftUI3 A simple todo app which aims to demonstrate some new concepts from SwiftUI 3 Description This is a simple todo app built to demonstrat

Roman Luzgin 50 Nov 1, 2022
A package that allows you to easily enable the Xcode canvas to a UIKit view.

UIViewCanvas This package allows you to enable a SwiftUI Xcode canva to a UIView or a entire ViewController. Why? Run emulator everytime you need to t

Wender 14 Jun 9, 2022
Deck is a library that provides a UI to reproduce stacked cards for SwiftUI.

Deck Deck is a library that provides a UI to reproduce stacked cards for SwiftUI. RPReplay_Final1624531727.mov Usage struct Card: View { var data

1amageek 21 Dec 14, 2022
A cooking book provides recipes to perform certain action on SwiftUI

SwiftUI Recipes This is like a cooking book. provides recipes to perform certain action on SwiftUI Every Project will contain as many SwiftUI views as

Julio Ismael Robles 2 Nov 23, 2021
📱 Very simple and lightweight messenger using Firebase

?? Very simple and lightweight messenger using Firebase ??. It is a training project for the practice of MVVM architecture.

Daniel Tvorun 2 Jun 26, 2022
Reusable & customizable SwiftUI settings sheet as a Swift package

PackAPrefPane Reusable & customizable SwiftUI settings sheet as a Swift package Features Swift package 100% Swift 99% SwiftUI Simple design Lightweigh

W1W1-M 9 Nov 6, 2022
Swift package adding extensions to SwiftUI.

swiftui-extensions SwiftUIX is an umpteenth package containing extensions for Apple's SwiftUI framework. Content The package currently provides the fo

Alexandre H. Saad 2 Jun 13, 2022
The app provides additional actions for the Shortcuts app on macOS and iOS.

Actions Supercharge your shortcuts The app provides additional actions for the Shortcuts app on macOS and iOS. Submit action idea (Submit an issue bef

Sindre Sorhus 1.2k Dec 29, 2022