-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from yoman07/feature/follow_button
Feature/follow button
- Loading branch information
Showing
10 changed files
with
225 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 0.1.4 | ||
- fixing bugs for getting location permission | ||
- localize me button as example | ||
|
||
# 0.1.3 | ||
|
||
- swift 3.1 | ||
- config for region tracking | ||
- improvements in asking for location permission | ||
|
||
# 0.1.1 | ||
- heading tracking | ||
|
||
# 0.1.0 | ||
- background location tracking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Example/SwiftBackgroundLocation/Extensions/MKMapView+Center.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import MapKit | ||
|
||
extension MKMapView { | ||
public func centerCamera(to location: CLLocation? = nil, distance: Double = 500, pitch: CGFloat = 0, heading: Double? = 0, animated: Bool = false) { | ||
let coordinate: CLLocationCoordinate2D = location?.coordinate ?? camera.centerCoordinate | ||
|
||
let c = MKMapCamera(lookingAtCenter: coordinate, fromDistance: distance, pitch: pitch, heading: heading ?? 0) | ||
setCamera(c, animated: animated) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Example/SwiftBackgroundLocation/Extensions/ViewController+LocalizeMe.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import MapKit | ||
|
||
extension ViewController: UIGestureRecognizerDelegate { | ||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { | ||
return true | ||
} | ||
|
||
func didDragMap(gestureRecognizer: UIGestureRecognizer) { | ||
if (gestureRecognizer.state == UIGestureRecognizerState.began) { | ||
localizeMeButton.localizeMeState = .unlocalized | ||
} | ||
} | ||
|
||
func setUpLocalizeMeButton() { | ||
|
||
let mapDragRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.didDragMap(gestureRecognizer:))) | ||
mapDragRecognizer.delegate = self | ||
self.view.addGestureRecognizer(mapDragRecognizer) | ||
|
||
localizeMeButton.listener = { [weak self] localizeMeState in | ||
switch localizeMeState { | ||
case .localized: | ||
self?.localizeMeManager.stop() | ||
self?.localizeMeManager.manager(for: .whenInUse, completion: { result in | ||
if case let .Success(manager) = result { | ||
manager.startUpdatingLocation(isHeadingEnabled: false) { [weak self] result in | ||
if case let .Success(locationHeading) = result, let location = locationHeading.location { | ||
self?.mapView.centerCamera(to: location) | ||
} | ||
} | ||
} | ||
}) | ||
case .unlocalized: | ||
self?.localizeMeManager.stop() | ||
case .navigated: | ||
self?.localizeMeManager.stop() | ||
self?.localizeMeManager.manager(for: .whenInUse, completion: { result in | ||
if case let .Success(manager) = result { | ||
manager.startUpdatingLocation(isHeadingEnabled: true) { [weak self] result in | ||
if case let .Success(locationHeading) = result { | ||
self?.mapView.centerCamera(to: locationHeading.location, heading: locationHeading.heading?.trueHeading) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Example/SwiftBackgroundLocation/Views/LocalizeMeButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import UIKit | ||
|
||
class LocalizeMeButton: UIButton { | ||
typealias LocalizeMeButtonOnTouchListener = ((LocalizeMeState) -> ()) | ||
var listener: LocalizeMeButtonOnTouchListener? | ||
|
||
var localizeMeState: LocalizeMeState = .unlocalized { | ||
didSet { | ||
switch localizeMeState { | ||
case .localized: | ||
setTitle("Localized", for: .normal) | ||
case .unlocalized: | ||
setTitle("Unlocalized", for: .normal) | ||
case .navigated: | ||
setTitle("Navigated", for: .normal) | ||
} | ||
|
||
listener?(localizeMeState) | ||
} | ||
} | ||
|
||
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { | ||
switch localizeMeState { | ||
case .localized: | ||
localizeMeState = .navigated | ||
case .unlocalized: | ||
localizeMeState = .localized | ||
case .navigated: | ||
localizeMeState = .localized | ||
} | ||
} | ||
|
||
enum LocalizeMeState { | ||
case localized, unlocalized, navigated | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.