Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alessiorubicini/locationpickerforswiftui
A SwiftUI view for interactive geographic coordinates input.
https://github.com/alessiorubicini/locationpickerforswiftui
geographic swift swift-package swiftui swiftui-package swiftuilocation
Last synced: about 1 month ago
JSON representation
A SwiftUI view for interactive geographic coordinates input.
- Host: GitHub
- URL: https://github.com/alessiorubicini/locationpickerforswiftui
- Owner: alessiorubicini
- License: mit
- Created: 2021-08-13T13:59:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-01T09:33:28.000Z (about 1 year ago)
- Last Synced: 2024-11-17T17:40:26.995Z (about 2 months ago)
- Topics: geographic, swift, swift-package, swiftui, swiftui-package, swiftuilocation
- Language: Swift
- Homepage:
- Size: 15.9 MB
- Stars: 32
- Watchers: 2
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LocationPicker for SwiftUI
`LocationPicker for SwiftUI` is a Swift package that provides an easy-to-use SwiftUI view for interactive input of geographic coordinates.
## Usage
All you need to do is to pass to the `LocationPicker` view a binding to a property of type `CLLocationCoordinate2D` (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.
![Location Picker](./Resources/LocationPickerForSwiftUI.png)
## Example
Here's a short usage example. You can find the full code in [UsageExample.swift](https://github.com/alessiorubicini/LocationPickerForSwiftUI/blob/master/Sources/LocationPicker/UsageExample.swift)
```swift
import SwiftUI
import MapKit
import LocationPickerstruct Example: View {
@State private var coordinates = CLLocationCoordinate2D(latitude: 37.333747, longitude: -122.011448)
@State private var showSheet = falsevar body: some View {
VStack {
Text("\(coordinates.latitude), \(coordinates.longitude)")
Button("Select location") {
self.showSheet.toggle()
}
}.sheet(isPresented: $showSheet) {
LocationPicker(instructions: "Tap to select coordinates", coordinates: $coordinates, dismissOnSelection: true)
}
}
```## Installation
Required:
- iOS 14.0 or above
- Xcode 12.0 or aboveIn Xcode go to `File -> Add Package Dependencies...` and paste in the repo's url: `https://github.com/alessiorubicini/LocationPickerForSwiftUI`.
Then choose the main branch or the version you desire.## License
Copyright 2022 (©) Alessio Rubicini.
The license for this repository is MIT License.
Please see the [LICENSE](LICENSE) file for full reference.