Giter Site home page Giter Site logo

fivesheepco / mapitempicker Goto Github PK

View Code? Open in Web Editor NEW
22.0 1.0 0.0 129 KB

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

License: MIT License

Swift 100.00%
ios mapkit spm swift swift-package-manager swiftpackage swiftpackagemanager swiftui swiftui-components

mapitempicker's Introduction

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

GithubCI_Status Quintschaf_Badge LICENSE_BADGE

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

.mapItemPickerSheet(isPresented: $showsSheet) { mapItem in
    print("Map Item:", mapItem)
}

Customizable View

.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

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

mapitempicker's People

Contributors

jannthomas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mapitempicker's Issues

Package Resolution Failed

Thank you for making this dependency but getting an error of "Package Resolution Failed" while adding it to the SwiftUI package list.

Error after adding to project

Hi, i am getting the following errors when adding your project as dependency:

MapItemController line 57: Referencing instance method 'removingDuplicates()' on 'Array' requires that 'MapItemImage' conform to 'Hashable'

SearchSheet line 41: Incorrect argument label in call (have 'object:', expected 'subject:')

It is enough to add your package into the project and run the project without using your stuff.

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.