Skip to content

Commit

Permalink
Merge pull request #63 from soundscape-community/bugfix/62-apple-maps…
Browse files Browse the repository at this point in the history
…-pin

Fix Apple Maps URL to create pin at location
  • Loading branch information
steinbro authored Oct 24, 2023
2 parents 19f3c3a + ec7e30d commit 9759101
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions apps/ios/GuideDogs/Code/App/ExternalNavigationApps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ enum ExternalNavigationApps: String, CaseIterable{
case .appleMaps: return "Apple Maps"
}
}
func url(location: CLLocation) -> URL? {
func url(location: CLLocation, label: String) -> URL? {
// Zoom level for all supported map apps and sites
let zoom = 10
let escapedLabel = label.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) ?? "Location"
switch self {
case .appleMaps: return URL(string: "https://maps.apple.com/?sll=\(location.coordinate.latitude),\(location.coordinate.longitude)&z=\(zoom)&t=s")
case .appleMaps: return URL(string: "https://maps.apple.com/?ll=\(location.coordinate.latitude),\(location.coordinate.longitude)&z=\(zoom)&q=\(escapedLabel)")
case .googleMaps: return URL(string: "https://www.google.com/maps/search/?api=1&query=\(location.coordinate.latitude)%2C\(location.coordinate.longitude)")
case .waze: return URL(string: "https://www.waze.com/ul?ll=\(location.coordinate.latitude)%2C\(location.coordinate.longitude)&navigate=yes&zoom=\(zoom)")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ extension UIAlertController {
}

/// Create and return a `UIAlertController` that is able to open an external maps app to a given destination
convenience init(openInExternalWithLocation: CLLocation, preferredStyle: UIAlertController.Style, handler: ((ExternalNavigationApps?) -> Void)? = nil) {
convenience init(openInExternalWithLocation: CLLocation, label: String, preferredStyle: UIAlertController.Style, handler: ((ExternalNavigationApps?) -> Void)? = nil) {
// Create alert actions
let actions = ExternalNavigationApps.allCases.compactMap { (mapApp) -> UIAlertAction? in
print("Processing app: \(mapApp)")
print("location: \(openInExternalWithLocation)")
guard let url = mapApp.url(location: openInExternalWithLocation) else {
guard let url = mapApp.url(location: openInExternalWithLocation, label: label) else {
print("Unable to construct URL for share to external maps ap")
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class ExpandableMapViewController: UIViewController {
if let locationDetail = locationDetail {
// Create and configure the alert controller.
//let alert = UIAlertController(title: GDLocalizedString("general.alert.choose_an_app"), message: nil, preferredStyle: .actionSheet)
let alert = UIAlertController(openInExternalWithLocation: locationDetail.location, preferredStyle: .actionSheet) { [weak self] (mapsApp) in
let alert = UIAlertController(openInExternalWithLocation: locationDetail.location, label: locationDetail.displayName, preferredStyle: .actionSheet) { [weak self] (mapsApp) in
print("Share to external maps app completion called")
if let mapsApp = mapsApp {
print("Map app: \(mapsApp)")
Expand Down

0 comments on commit 9759101

Please sign in to comment.