Additional Location Details

MapsIndoors locations can have a variety of additional details, such as phone numbers, websites, emails, and opening hours. These details can be managed in the CMS, read this articlearrow-up-right for how to set them up or edit them.


Accessing Additional Details in Code

Each MPLocation object contains an additionalDetails property, which is a list of detail objects. Each detail has a type, value, key, and other fields. You can iterate through these details and handle them according to their type.

Print all details example
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)
    }
}

Note: A single location can have multiple details of the same type. Use unique keys to distinguish them.

Filtering and Printing Specific Details

Your locations can have multiple details, in this case the location has multiple phone numbers: customer service and sales with the respective keys customerService and sales, you can filter and print them by key:

Last updated

Was this helpful?