Additional Location Details
Accessing Additional Details in Code
func printDetails(location: MPLocation) {
// Get and iterate over the list of additional details from the location
for detail in location.additionalDetails ?? [] {
// Only print active details
guard detail.active ?? false else { continue }
let string = switch detail.detailType?.type {
case .text:
// Text details (e.g. description)
"\(location.name) additional information: \(detail.value ?? "nil")"
case .phone:
// Phone details (all details have a key for identification)
"\(location.name)'s phone number (\(detail.key ?? "nil")): \(detail.value ?? "nil")"
case .url:
// URL details (details can have user friendly display text)
"\(location.name)'s website: \(detail.value ?? "nil") (label: \(detail.displayText ?? "nil"))"
case .email:
// Email details (details can be supplied with an icon URL)
"\(location.name)'s email: \(detail.value ?? "nil") (icon: \(detail.icon ?? "nil"))"
case .openingHours:
// Opening hours (has a special field 'openingHours' that is only used for this)
"\(location.name) opening hours: \(detail.openingHours?.description ?? "No opening hours")"
case .none:
"Unknown detail type for \(location.name)"
case .some(_):
"Unknown detail type for \(location.name)"
}
print(string)
}
}Filtering and Printing Specific Details
Last updated
Was this helpful?