forked from BottleRocketStudios/iOS-UtiliKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into release/1.8.0
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 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
32 changes: 32 additions & 0 deletions
32
Sources/UtiliKit/General/CLLocationCoordinate2D+Extensions.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,32 @@ | ||
// | ||
// CLLocationCoordinate2D+Extensions.swift | ||
// UtiliKit-iOS | ||
// | ||
// Created by Andrew Winn on 8/24/21. | ||
// Copyright © 2021 Bottle Rocket Studios. All rights reserved. | ||
// | ||
|
||
import CoreLocation | ||
|
||
public extension CLLocationCoordinate2D { | ||
|
||
/// Checks if a coordinate is valid. Attempting to use an invalid coordinate (e.g. by setting a map region to center on it) will crash the app. | ||
/// | ||
/// A coordinate is considered **invalid** if it meets at least one of the following criteria: | ||
/// - Its latitude is greater than 90 degrees or less than -90 degrees. | ||
/// - Its longitude is greater than 180 degrees or less than -180 degrees. | ||
/// | ||
/// An invalid coordinate can be generated from: | ||
/// - Invalid data from an API | ||
/// - `mkMapView.userLocation.coordinate` is not an optional property and will provide an invalid coordinate when the user is not sharing their location. | ||
/// - `locationManager.location.coordinate` is an optional property but may still provide an invalid coordinate (e.g. when the user has revoked location permissions while the app is running after previously granting) | ||
var isValid: Bool { | ||
if CLLocationCoordinate2DIsValid(self) { | ||
return true | ||
} | ||
debugPrint("================================================") | ||
debugPrint("Invalid CLLocationCoordinate2D Detected: \(self)") | ||
debugPrint("================================================") | ||
return false | ||
} | ||
} |
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