Swiftpack.co - xattacker/MapScaleView_iOS_API as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
xattacker/MapScaleView_iOS_API
an iOS Map ScaleView UI Component
.package(url: "https://github.com/xattacker/MapScaleView_iOS_API.git", from: "1.2.2")

MapScaleView_iOS_API

an iOS swift Map ScaleView UI View component

Development Target: iOS 10

Provide a scale view with iOS MKMapView:
图片替换文本

Installation

Cocoapods

MapScaleView can be added to your project using CocoaPods 0.36 or later by adding the following line to your Podfile:

pod 'MapScaleView'

Swift Package Manager

To add MapScaleView to a Swift Package Manager based project, add:

.package(url: "https://github.com/xattacker/MapScaleView_iOS_API.git", .upToNextMajor(from: "1.2.0")),

to your Package.swift files dependencies array.

How to use:

import MapScaleView

let scale_view: UIMapScaleView

scale_view.mapScaleCalculator = mapView //  setup with MKMapView
scale_view.outlineColor = UIColor.white
scale_view.bodyColor = UIColor.black
scale_view.direction = .leftToRight // set the bar start direction in leftToRight / rightToRight, default is leftToRight
scale_view.unit = .metric // you could set distance unit in metric / imperial, default is metric mode


// implement from MKMapViewDelegate
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool)
{
   // udpate with mapView
   scaleView.setNeedsLayout()
}

How to support Google Map API:

import MapScaleView
import GoogleMaps

let scale_view: UIMapScaleView

scale_view.mapScaleCalculator = mapView //  setup with GMSMapView

// implement from GMSMapViewDelegate
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition)
{
   // udpate with mapView
   scaleView.setNeedsLayout()
}

// let GMSMapView implement protocol MapScaleCalculator that make it could support ScaleView
extension GMSMapView: MapScaleCalculator
{
    public var metersPerPixel: CGFloat
    {
        let topLeft = self.projection.visibleRegion().farLeft
        let bottomLeft = self.projection.visibleRegion().nearLeft
        let lat = CGFloat(abs(Float(topLeft.latitude - bottomLeft.latitude)))
        let metersPerPixel = CGFloat((cos(lat * .pi / 180) * 2 * .pi) * 6378137 / CGFloat((256 * pow(2, self.camera.zoom))))
        return metersPerPixel
    }
}

GitHub

link
Stars: 7
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

removed Pods related files
23 weeks ago

avoid uploading pods related files

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics