Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fivesheepco/mapitempicker

A simple, yet highly customizable and powerful location picker for SwiftUI.
https://github.com/fivesheepco/mapitempicker

ios mapkit spm swift swift-package-manager swiftpackage swiftpackagemanager swiftui swiftui-components

Last synced: 19 days ago
JSON representation

A simple, yet highly customizable and powerful location picker for SwiftUI.

Awesome Lists containing this project

README

        

# MapItemPicker πŸ—ΊοΈπŸ“

[![GithubCI_Status]][GithubCI_URL]
[![Quintschaf_Badge]](https://quintschaf.com)
[![LICENSE_BADGE]][LICENSE_URL]

MapItemPicker is a simple, yet highly customizable and powerful location picker for SwiftUI.


Sheet for New York City
Search for Airport in Germany
Sheet for Central Park
Picker Inside a Full Screen Overlay

## Description

A lot of apps need some kind of view to find and select locations. Sadly, Apple doesn't offer a view for this in their frameworks and a lot of the information displayed in the Maps app that makes it easy to search for and discover map items is not exposed on `MKMapItem`. MapItemPicker uses data from MapKit, OpenStreetMaps and Wikidata to deliver a simple yet beautiful and comprehensive map item picker.

## Example Code

### Simple Picker

#### Convenience Method
```Swift
.mapItemPickerSheet(isPresented: $showsSheet) { mapItem in
print("Map Item:", mapItem)
}
```

#### Customizable View
```Swift
.fullScreenCover(isPresented: $showsSheet) {
NavigationView {
MapItemPicker(
primaryMapItemAction: .init(
title: "select",
imageName: "checkmark.circle.fill",
handler: { mapItem in
print("Map Item:", mapItem)
return true
}
)
)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("cancel") {
showsSheet = false
}
}
}
.navigationTitle(Text("select"))
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar)
}
}
```

### Advanced Map View with Configured Standard View

```Swift
MapItemPicker(
annotations: [MKPointAnnotation.chicago],
annotationView: { annotation in
MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: nil)
},
annotationSelectionHandler: { annotation in
print("selected:", annotation)
},
overlays: [MKPolyline.newYorkToLosAngeles],
overlayRenderer: { overlay in
MKPolylineRenderer(polyline: overlay as! MKPolyline, color: .red)
},
primaryMapItemAction: .init(title: "select", imageName: "checkmark.circle.fill", handler: { mapItem in
print("Map Item:", mapItem)
return true
}),
additionalMapItemActions: [
.init(
title: "addTo",
imageName: "plus.square",
subActions: [
.init(title: "Collection A", imageName: "square.on.square", handler: { mapItem in return false }),
.init(title: "Collection B", imageName: "square.on.square", handler: { mapItem in return false })
]
)
],
showsLocationButton: false,
additionalTopRightButtons: [
.init(
imageName: "magnifyingglass",
handler: { searchControllerShown = true }
)
],
initialRegion: MKCoordinateRegion.unitedStates,
standardView: { Text("Standard View") },
searchControllerShown: $searchControllerShown,
standardSearchView: { Text("Search View") }
)
```

## Localization

MapItemPicker contains localizations for categories, titles of sections in the views and other strings. Currently, only English and German are supported. If you can provide localization for any other language, please submit a PR. You can copy the strings from the English `Localizable.strings` file at `Sources/MapItemPicker/Resources/en.lproj`. It's not a lot of localization keys, you will propably be done in 5 minutes.

## TODO

- [ ] A lot of MapItems currently have a type of simply 'Location' (Localization Key 'mapItem.type.item') before loading Wikidata and/or OpenStreetMaps data. This includes cities, mountains and other items for which Apple doesn't provide a `MKPointOfInterestCategory` and should be resolved.
- [ ] Add more datasources. This can be free ones like Wikidata and OpenStreetMaps, as well as paid ones for which each application can provide their own API key.
- [ ] Add the ability to edit opening hours etc. and report back to OpenStreetMaps
- [ ] Add more filters like "Is Open" in Search
- [ ] Add Unit Tests
- [ ] Add example App with UI Tests
- [ ] Compile Documentation

[GithubCI_Status]: https://github.com/quintschaf/MapItemPicker/actions/workflows/ci.yml/badge.svg?branch=main
[GithubCI_URL]: https://github.com/quintschaf/MapItemPicker/actions/workflows/ci.yml
[Quintschaf_Badge]: https://badgen.net/badge/Built%20and%20maintained%20by/Quintschaf/cyan?icon=https://quintschaf.com/assets/logo.svg
[LICENSE_BADGE]: https://badgen.net/github/license/Quintschaf/MapItemPicker
[LICENSE_URL]: https://github.com/Quintschaf/MapItemPicker/blob/master/LICENSE