Add lead workflows, PDF signing, AR projects and photo gallery integration
This commit is contained in:
28
GasTankAR/Services/CustomerLocationService.swift
Normal file
28
GasTankAR/Services/CustomerLocationService.swift
Normal file
@ -0,0 +1,28 @@
|
||||
import MapKit
|
||||
|
||||
@MainActor
|
||||
protocol CustomerLocationService {
|
||||
func coordinate(for address: String) async throws -> CLLocationCoordinate2D
|
||||
}
|
||||
|
||||
enum CustomerLocationError: Error {
|
||||
case notFound
|
||||
}
|
||||
|
||||
@MainActor
|
||||
struct AppleMapsCustomerLocationService: CustomerLocationService {
|
||||
func coordinate(for address: String) async throws -> CLLocationCoordinate2D {
|
||||
guard let request = MKGeocodingRequest(addressString: address) else {
|
||||
throw CustomerLocationError.notFound
|
||||
}
|
||||
let items: [MKMapItem]
|
||||
do {
|
||||
items = try await request.mapItems
|
||||
} catch let error as MKError where error.code == .placemarkNotFound {
|
||||
throw CustomerLocationError.notFound
|
||||
}
|
||||
try Task.checkCancellation()
|
||||
guard let item = items.first else { throw CustomerLocationError.notFound }
|
||||
return item.location.coordinate
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user