Commit 941eb827 authored by Ariba Siddiqui's avatar Ariba Siddiqui
Browse files

Brian's code merge for searching places

parent 5f44abbf
File added
......@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
09AD0D752753EF1C00E400F7 /* MapSerachView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AD0D742753EF1C00E400F7 /* MapSerachView.swift */; };
09AD0D772753EF5000E400F7 /* LocationSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AD0D762753EF5000E400F7 /* LocationSearch.swift */; };
2517A35527502266006F2B81 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2517A35427502266006F2B81 /* AppDelegate.swift */; };
2517A35727502266006F2B81 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2517A35627502266006F2B81 /* SceneDelegate.swift */; };
2517A35927502266006F2B81 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2517A35827502266006F2B81 /* ViewController.swift */; };
......@@ -36,6 +38,8 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
09AD0D742753EF1C00E400F7 /* MapSerachView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapSerachView.swift; sourceTree = "<group>"; };
09AD0D762753EF5000E400F7 /* LocationSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearch.swift; sourceTree = "<group>"; };
2517A35127502266006F2B81 /* Location Tutorial.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Location Tutorial.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2517A35427502266006F2B81 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2517A35627502266006F2B81 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
......@@ -106,6 +110,8 @@
2517A35D2750226C006F2B81 /* Assets.xcassets */,
2517A35F2750226C006F2B81 /* LaunchScreen.storyboard */,
2517A3622750226C006F2B81 /* Info.plist */,
09AD0D742753EF1C00E400F7 /* MapSerachView.swift */,
09AD0D762753EF5000E400F7 /* LocationSearch.swift */,
);
path = "Location Tutorial";
sourceTree = "<group>";
......@@ -258,7 +264,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
09AD0D772753EF5000E400F7 /* LocationSearch.swift in Sources */,
2517A35927502266006F2B81 /* ViewController.swift in Sources */,
09AD0D752753EF1C00E400F7 /* MapSerachView.swift in Sources */,
2517A35527502266006F2B81 /* AppDelegate.swift in Sources */,
2517A35727502266006F2B81 /* SceneDelegate.swift in Sources */,
);
......
......@@ -31,6 +31,15 @@
<action selector="goButtonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="6wg-qh-SbU"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="bJs-lu-5Kb">
<rect key="frame" x="153" y="823" width="108" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="filled" title="Search"/>
<connections>
<segue destination="IYp-gh-PTG" kind="show" id="hbP-Na-7T8"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
......@@ -49,6 +58,16 @@
</objects>
<point key="canvasLocation" x="28.985507246376812" y="67.633928571428569"/>
</scene>
<!--SwiftUI View Hosting Controller-->
<scene sceneID="okH-7R-IPv">
<objects>
<hostingController id="IYp-gh-PTG" customClass="SwiftUIViewHostingController" customModule="Location_Tutorial" customModuleProvider="target" sceneMemberID="viewController">
<navigationItem key="navigationItem" id="fYL-Y4-EZ5"/>
</hostingController>
<placeholder placeholderIdentifier="IBFirstResponder" id="pFQ-df-iLn" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="830" y="68"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
......
//
// LocationFinder.swift
// MapKit Testing Search Functionality
//
// Created by Brian Porumb on 25.11.21.
//
import Foundation
import Combine
import MapKit
class LocationService: NSObject, ObservableObject {
enum LocationStatus: Equatable {
case idle
case noResults
case isSearching
case error(String)
case result
}
@Published var queryFragment: String = ""
@Published private(set) var status: LocationStatus = .idle
@Published private(set) var searchResults: [MKLocalSearchCompletion] = []
private var queryCancellable: AnyCancellable?
private let searchCompleter: MKLocalSearchCompleter!
init(searchCompleter: MKLocalSearchCompleter = MKLocalSearchCompleter()) {
self.searchCompleter = searchCompleter
super.init()
self.searchCompleter.delegate = self
queryCancellable = $queryFragment
.receive(on: DispatchQueue.main)
.debounce(for: .milliseconds(250), scheduler: RunLoop.main, options: nil)
.sink(receiveValue: { fragment in
self.status = .isSearching
if !fragment.isEmpty {
self.searchCompleter.queryFragment = fragment
} else {
self.status = .idle
self.searchResults = []
}
})
}
}
extension LocationService: MKLocalSearchCompleterDelegate {
func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
self.searchResults = completer.results.filter({ $0.subtitle == "" })
self.status = completer.results.isEmpty ? .noResults : .result
}
func completer(_ completer: MKLocalSearchCompleter, didFailWithError error: Error) {
self.status = .error(error.localizedDescription)
}
}
//
// ContentView.swift
// MapKit Testing Search Functionality
//
// Created by Brian Porumb on 25.11.21.
//
import SwiftUI
class SwiftUIViewHostingController: UIHostingController<ContentView> {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder, rootView: ContentView(locationService: LocationService()))
}
}
struct ContentView: View {
@ObservedObject var locationService: LocationService
var body: some View {
VStack {
Form {
Section(header: Text("Search")) {
ZStack(alignment: .trailing) {
TextField("Search", text: $locationService.queryFragment)
if locationService.status == .isSearching {
Image(systemName: "clock")
.foregroundColor(Color.gray)
}
}
}
Section(header: Text("Results")) {
List {
Group { () -> AnyView in
switch locationService.status {
case .noResults: return AnyView(Text("No Results"))
case .error(let description): return AnyView(Text("Error: \(description)"))
default: return AnyView(EmptyView())
}
}.foregroundColor(Color.gray)
ForEach(locationService.searchResults, id: \.self) {
completionResult in Text(completionResult.title)
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(locationService: LocationService())
}
}
//
// SwiftUIViewHostingController.swift
// Location Tutorial
//
// Created by Brian Porumb on 28.11.21.
//
import Foundation
struct ContentView: View {
@ObservedObject var locationService: LocationService
var body: some View {
VStack {
Form {
Section(header: Text("Search")) {
ZStack(alignment: .trailing) {
TextField("Search", text: $locationService.queryFragment)
if locationService.status == .isSearching {
Image(systemName: "clock")
.foregroundColor(Color.gray)
}
}
}
Section(header: Text("Results")) {
List {
Group { () -> AnyView in
switch locationService.status {
case .noResults: return AnyView(Text("No Results"))
case .error(let description): return AnyView(Text("Error: \(description)"))
default: return AnyView(EmptyView())
}
}.foregroundColor(Color.gray)
ForEach(locationService.searchResults, id: \.self) {
completionResult in Text(completionResult.title)
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(locationService: LocationService())
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
</view>
</objects>
</document>
# MapKit Directions
Code for routes in MapKit (part of iOS App Dev W21 coursework)
\ No newline at end of file
This project (a part of iOS App Dev W21 coursework) displays routes in MapKit from a user's location to a hard-coded location of "Cologne".
Result -
![img](https://git.rwth-aachen.de/ariba.rwth/mapkit-directions/-/blob/main/Simulator_Screen_Shot_-_iPhone_11_Pro_Max_-_2021-11-27_at_02.29.26.png)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment