GithubHelp home page GithubHelp logo

swiftui-mapview's Introduction

swiftui-mapview

Swift Version

Platforms

MKMapView in SwiftUI.

For iOS 14 and later, please use Apple's official Map view.

Social Preview (Click the image to see the full screenshot)

Install

Using Xcode, select File -> Swift Packages -> Add Package Dependency and enter https://github.com/sgade/swiftui-mapview.

Usage

In your view, add the map. See the example project for how to integrate the map view.

import SwiftUIMapView

struct ContentView: View {
    var body: some View {
        MapView()
    }
}

General

Map type

MapView(mapType: .standard)

User location

Showing the current user location

The current location can be shown on the map. By default, this is true. Note that the application requires permission to access the current user location. See the documentation on MapView.showsUserLocation for more information.

MapView(showsUserLocation: true)

Tracking the user's location

MapView(userTrackingMode: .follow)

Region

Setting the visible region center

The binding passed in for center defines the visible region. Setting it to nil will use the map's default region when loaded. It is also updated when the visible region changes.

@State var center: CLLocationCoordinate2D?

MapView(center: self.$center)

Setting the visible region zoom

The binding passed in for zoom defines the visible region span. A default zoom is used if you do not specify any value. It is also updated when the visible region changes.

@State var zoom: MKCoordinateSpan

MapView(zoom: self.$zoom)

Annotations

Adding annotations

Annotations are represented as objects of a custom class that implements the MapViewAnnotation protocol. It might be helpful to sublcass from existing classes like MKPlacemark.

let annotations: [MapViewAnnotation] = ...

MapView(annotation: self.annotations)

Selecting annotations

A list of selected annotations can be passed in via binding. Selecting an annotations updates the binding, and the other way around.

@State var selectedAnnotations: [MapViewAnnotation] = []

MapView(selectedAnnotations: self.$selectedAnnotations)

Contributing

See the contributing guide.

License

This project is licensed unter the terms of the MIT license. See LICENSE for more information.

swiftui-mapview's People

Contributors

sgade avatar cowbellsolo avatar davdroman 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.