SwiftUIMap

SwiftUIMap 是 MapKit 最佳的 UIKit 封装!

安装

Swift 包管理器

目前,我们仅支持设置注释,但正在开发用户可添加标记的地图。

要求

安装

安装 SwiftUIMap 的首选方式是通过 Swift 包管理器

  1. 在 Xcode 中,打开你的项目,并导航到 FileAdd Packages...
  2. 粘贴仓库 URL (https://github.com/Mcrich23/SwiftUIMap) 并点击 Next
  3. 对于 Rules,选择 Up To Next Major Version (基础版本设置为 1.1.0)。
  4. 点击 Finish
  5. 选中 Mcrich23-Toolkit
  6. 点击 Add To Project

用法

注意:要使用 SwiftUIMap 中的地图,你需要导入 MapKit

AnnotationMapView

ExistingMapView (
    zoom: 0.4, // Starting Zoom of Map (Range: 0-1, Lower is closer in)
    address: "Seattle, Wa", // Starting address in the Center of the Map (use this or coordinates)
    points: [
        Annotations(
            title: "Townhall", // Top line on map
            subtitle: "Newly Remodeled", // Underneath top line when clicked
            location: .address("1119 8th Ave, Seattle, WA, 98101, United States"), // Location for point
            glyphImage: .defaultIcon, // Glyph icon on map point
            markerTintColor: .red, // Marker background
            glyphTintColor: .white, // Glyph icon color
            displayPriority: .required // How markers are shown
        )
    ],
    isUserLocationVisible: $isUserLocationVisible, // Binding for if isUserLocationVisible
    selected: { Title, Subtitle, Address, isCluster in // Action When Marker is Selected (Returns title, subtitle, and address in annotation along with if it's in a cluster)
        print("tapped \(Address)")
    }, deselected: { // Action When Marker is Deselceted
        print("deselected annotation")
    }, advancedModifiers: { // Full access to MKMapView modifiers
        map.alpha = 0.4
    }
)

MutableMapView

MutableMapView (
    zoom: 0.4, // Starting Zoom of Map (Range: 0-1, Lower is closer in)
    address: "Seattle, Wa", // Starting address in the Center of the Map (use this or coordinates)
    isFirstResponder: $isFirstResponder // Binding for if isFirstResponder
)

修饰符

...
    .pointsOfInterest(.excludingAll) // Filter Points of Interest (exclude or include all)
    .pointOfInterestCategories(include: [.atm]) // Filter Points of Interest to only include things in an array
    .pointOfInterestCategories(exclude: [.airport]) // Filter Points of Interest to include everything except things in an array
    .showCompass(false) // Show Compass (true or false)
    .showScale(false) // Show Scale (true or false)
    .showTraffic(false) // Show Traffic (true or false)
    .showBuildings(false) // Show Buildings (true or false)
    .mapType(.satellite) // Different types of map (Standard, MutedStandard, Hybrid, HybridFlyover, Satellite, SatelliteFlyover)
    .camera(MKMapCamera(lookingAtCenter: loc, fromDistance: .pi, pitch: 4, heading: .pi)) // Customize the camera angle
    .cameraBoundary(MKMapView.CameraBoundary(coordinateRegion: MKCoordinateRegion(center: loc, span: MKCoordinateSpan(latitudeDelta: 4, longitudeDelta: 4)))) // Customize the camera boundary
    .cameraZoomRange(MKMapView.CameraZoomRange(minCenterCoordinateDistance: CLLocationDistance(600))) // Customize the zoom range (minCenterCoordinateDistance and maxCenterCoordinateDistance)
    .isPitchEnabled(true) // Enable or disable the use of pitch
    .isUserInteractionEnabled(true) // Enable or disable interaction
    .isZoomEnabled(true) // Enable or disable the use of zoom
    .isRotateEnabled(true) // Enable or disable the use of rotation
    .isScrollEnabled(true) // Enable or disable the use of scroll
    .isMultipleTouchEnabled(true) // Enable or disable the use of multi-touch
    .userTrackingMode(.none) // Sets the mode for user tracking (must have permission to track user)

MapSearchView

MapSearchView(resultTypes: .address, pointOfInterestFilter: .init(including: [.restaurant]), onSelect: { address in //Address passed back
    zoom = 0.2 // Zooms out
    DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(650), execute: { // Wait to go to the new place
        self.address = address // Change central address
    })
})

defaultCameraAngle

SwiftUIMap.defaultCameraAngle( // Get Default Camera Angle
    location: CLLocationCoordinate2D( // Center coordinates
        latitude: lat, // Latitude for center coordinate
        longitude: long // Longitude for center coordinate
    ), 
    zoom: zoom // How far zoomed in the camera is
)

许可

ScrollKit 基于 MIT 许可发布。更多信息请查看 LICENSE 文件。