GithubHelp home page GithubHelp logo

bbdaniell / locationpickerforswiftui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alessiorubicini/locationpickerforswiftui

0.0 0.0 0.0 568 KB

A Swift package that provides a SwiftUI view for interactive input of geographic coordinates

License: MIT License

Swift 100.00%

locationpickerforswiftui's Introduction

LocationPicker for SwiftUI

LocationPicker for SwiftUI is a simple and lightweight Swift package that provides a SwiftUI view for interactive input of geographic coordinates.

Usage

First you need to create a view with a @Binding property of CLLocationCoordinate2D type (remember to import the MapKit framework!) inside. 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).

License

Copyright 2021 (©) Alessio Rubicini.

The license for this repository is MIT License.

Please see the LICENSE file for full reference.

locationpickerforswiftui's People

Contributors

alessiorubicini avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.