From 110989eb7aa019cec99c81f3e6d7824870717281 Mon Sep 17 00:00:00 2001 From: Darren Jones Date: Thu, 24 Dec 2020 12:13:59 +0000 Subject: [PATCH] Added CLLocationCoordinate2D locationIsInside --- DJSwiftHelpers.xcodeproj/project.pbxproj | 8 ++++++++ .../Helpers/CLLocationCoordinate2D.swift | 18 ++++++++++++++++++ README.md | 7 +++++++ 3 files changed, 33 insertions(+) create mode 100644 DJSwiftHelpers/Helpers/CLLocationCoordinate2D.swift diff --git a/DJSwiftHelpers.xcodeproj/project.pbxproj b/DJSwiftHelpers.xcodeproj/project.pbxproj index d038ffe..c3ef8a6 100644 --- a/DJSwiftHelpers.xcodeproj/project.pbxproj +++ b/DJSwiftHelpers.xcodeproj/project.pbxproj @@ -37,6 +37,9 @@ 621B3C2D255D467000A5E77F /* UIWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620F6A4F250BC1E400B10032 /* UIWindow.swift */; }; 621B3C2E255D467000A5E77F /* UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620F6A4B250BBCD700B10032 /* UIViewController.swift */; }; 621B3C2F255D467000A5E77F /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620F6A49250BBC4B00B10032 /* UIImage.swift */; }; + 625380722594BCE900C58B2F /* CLLocationCoordinate2D.swift in Sources */ = {isa = PBXBuildFile; fileRef = 625380712594BCE900C58B2F /* CLLocationCoordinate2D.swift */; }; + 625380762594BDDD00C58B2F /* CLLocationCoordinate2D.swift in Sources */ = {isa = PBXBuildFile; fileRef = 625380712594BCE900C58B2F /* CLLocationCoordinate2D.swift */; }; + 6253807A2594BDDD00C58B2F /* CLLocationCoordinate2D.swift in Sources */ = {isa = PBXBuildFile; fileRef = 625380712594BCE900C58B2F /* CLLocationCoordinate2D.swift */; }; 627631A7255D512F005C09B1 /* DJSwiftHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 627631A6255D512F005C09B1 /* DJSwiftHelpers.swift */; }; 62D6CDE9255BFCCB00ABD216 /* Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D6CDE8255BFCCB00ABD216 /* Decodable.swift */; }; 62D6CDEC255BFDA900ABD216 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D6CDEB255BFDA900ABD216 /* Date.swift */; }; @@ -72,6 +75,7 @@ 620F6A4D250BBCE900B10032 /* UserDefaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDefaults.swift; sourceTree = ""; }; 620F6A4F250BC1E400B10032 /* UIWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIWindow.swift; sourceTree = ""; }; 621B3C35255D467000A5E77F /* DJSwiftHelpers_Extension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DJSwiftHelpers_Extension.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 625380712594BCE900C58B2F /* CLLocationCoordinate2D.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLLocationCoordinate2D.swift; sourceTree = ""; }; 627631A6255D512F005C09B1 /* DJSwiftHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DJSwiftHelpers.swift; sourceTree = ""; }; 62D6CDE8255BFCCB00ABD216 /* Decodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Decodable.swift; sourceTree = ""; }; 62D6CDEB255BFDA900ABD216 /* Date.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = ""; }; @@ -138,6 +142,7 @@ isa = PBXGroup; children = ( 620F6A32250BB78100B10032 /* Array.swift */, + 625380712594BCE900C58B2F /* CLLocationCoordinate2D.swift */, 62D6CDEB255BFDA900ABD216 /* Date.swift */, 627631A6255D512F005C09B1 /* DJSwiftHelpers.swift */, 620F6A34250BB78200B10032 /* String.swift */, @@ -320,6 +325,7 @@ 620F6A3B250BB78200B10032 /* UIColor.swift in Sources */, 62D6CDEF255BFFA300ABD216 /* URLResponse.swift in Sources */, 62D6CDEC255BFDA900ABD216 /* Date.swift in Sources */, + 625380722594BCE900C58B2F /* CLLocationCoordinate2D.swift in Sources */, 62D6CDF5255C01F400ABD216 /* UILabel.swift in Sources */, 62D6CDE9255BFCCB00ABD216 /* Decodable.swift in Sources */, 620F6A50250BC1E400B10032 /* UIWindow.swift in Sources */, @@ -344,6 +350,7 @@ 621B3C28255D467000A5E77F /* UIColor.swift in Sources */, 621B3C29255D467000A5E77F /* URLResponse.swift in Sources */, 621B3C2A255D467000A5E77F /* Date.swift in Sources */, + 625380762594BDDD00C58B2F /* CLLocationCoordinate2D.swift in Sources */, 621B3C2B255D467000A5E77F /* UILabel.swift in Sources */, 621B3C2C255D467000A5E77F /* Decodable.swift in Sources */, 621B3C2D255D467000A5E77F /* UIWindow.swift in Sources */, @@ -360,6 +367,7 @@ 62DF507D256E9A8D00C88FF7 /* DJSwiftHelpers.swift in Sources */, 62DF50AD256E9AA800C88FF7 /* URLSession.swift in Sources */, 62DF5089256E9A9400C88FF7 /* UIColor.swift in Sources */, + 6253807A2594BDDD00C58B2F /* CLLocationCoordinate2D.swift in Sources */, 62DF50B1256E9AAA00C88FF7 /* UserDefaults.swift in Sources */, 62DF5078256E9A8900C88FF7 /* Array.swift in Sources */, 62DF5081256E9A9000C88FF7 /* String.swift in Sources */, diff --git a/DJSwiftHelpers/Helpers/CLLocationCoordinate2D.swift b/DJSwiftHelpers/Helpers/CLLocationCoordinate2D.swift new file mode 100644 index 0000000..e848886 --- /dev/null +++ b/DJSwiftHelpers/Helpers/CLLocationCoordinate2D.swift @@ -0,0 +1,18 @@ +// +// CLLocationCoordinate2D.swift +// DJSwiftHelpers +// +// Created by Darren Jones on 24/12/2020. +// Copyright © 2020 Dappological Ltd. All rights reserved. +// + +import Foundation +import CoreLocation + +extension CLLocationCoordinate2D { + + func locationIsInside(minLat:Double, maxLat:Double, minLong:Double, maxLong:Double) -> Bool { + + return self.latitude >= minLat && self.latitude <= maxLat && self.longitude >= minLong && self.longitude <= maxLong + } +} diff --git a/README.md b/README.md index e1b55fd..e58ec40 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,13 @@ Example: .uniques(by: \.surname) ``` +### CLLocationCoordinate2D +Determine if a location is within a bounding rect + +```swift +locationIsInside(minLat:Double, maxLat:Double, minLong:Double, maxLong:Double) -> Bool +``` + ### Date Adds additional seconds or minutes to a `Date`