Skip to content

Commit

Permalink
add route filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
cindy-x-liang authored and rs929 committed Aug 19, 2024
1 parent a70fa10 commit 5fb58bf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions TCAT/Controllers/HomeMapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class HomeMapViewController: UIViewController {

private let loadingIndicatorSize = CGSize.init(width: 40, height: 40)
private let userDefaults = UserDefaults.standard


override func viewDidLoad() {
super.viewDidLoad()
Expand Down
1 change: 0 additions & 1 deletion TCAT/Controllers/HomeOptionsCardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ class HomeOptionsCardViewController: UIViewController {
}

// MARK: - Get Search Results

/// Get Search Results
@objc func getPlaces(timer: Timer) {
if let userInfo = timer.userInfo as? [String: String],
Expand Down
1 change: 1 addition & 0 deletions TCAT/Controllers/SearchResultsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class SearchResultsViewController: UIViewController {
}

@objc private func getPlaces(timer: Timer) {
print("here")
if let userInfo = timer.userInfo as? [String: String],
let searchText = userInfo["searchText"],
!searchText.isEmpty {
Expand Down
14 changes: 13 additions & 1 deletion TCAT/Models/SearchManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class SearchManager: NSObject {
private let networking: Networking = URLSession.shared.request
private let searchCompleter = MKLocalSearchCompleter()
private var searchResults = [MKLocalSearchCompletion]()

private let gshLat = 42.442558
private let gshLong = -76.485336

override private init() {
super.init()
Expand All @@ -41,6 +44,13 @@ class SearchManager: NSObject {
)
}
}
private func sortLocations(_ s1: Place, _ s2: Place) -> Bool {
let s1Check = pow((s1.latitude-(self.gshLat)),2.0) + pow((s1.longitude-(self.gshLong)),2.0)

let s2Check = pow((s2.latitude-(self.gshLat)),2.0) + pow((s2.longitude-(self.gshLong)),2.0)
return s1Check < s2Check
}


func performLookup(for query: String, completionHandler: @escaping SearchManagerCallback) {
getAppleSearchResults(searchText: query).observe { [weak self] result in
Expand All @@ -55,7 +65,9 @@ class SearchManager: NSObject {
// If the list of Apple Places for this query already exists in
// server cache, no further work is needed
if let applePlaces = response.data.applePlaces {
let searchResults = applePlaces + busStops
let updatedApplePlaces = applePlaces.sorted(by: self.sortLocations)

let searchResults = updatedApplePlaces + busStops
completionHandler(searchResults, nil)
} else {
// Otherwise, we need to perform the Apple Places lookup locally
Expand Down

0 comments on commit 5fb58bf

Please sign in to comment.