> For the complete documentation index, see [llms.txt](https://docs.mapsindoors.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mapsindoors.com/sdks-and-frameworks/ios/searching/searching-on-a-map.md).

# Searching on a Map

{% tabs %}
{% tab title="iOS v4" %}
Use the [`MPMapsIndoors.shared.locationsWith(query:filter:)`](https://app.mapsindoors.com/mapsindoors/reference/ios/4.1.3/documentation/mapsindoors/mapsindoorsshared/locationswith\(query:filter:\)) method to search for content in your MapsIndoors Solution.

**Setup a query for the nearest single best matching Location and display the result on the map​**

```swift
let filter = MPFilter()
let query = MPQuery()
query.query = "Office"
query.near = MPPoint(lat: 57.057964, lon: 9.9504112)
query.take = 1

let locations = await MPMapsIndoors.shared.locationsWith(query: query, filter: filter)
if let location = locations?.first {
    self.mapControl?.goTo(entity: location)
}

```

**Setup a query for a group of Locations and display the result on the map​**

```swift
let filter = MPFilter()
let query = MPQuery()
query.categories = ["Office"]
query.max = 50

let locations = await MPMapsIndoors.shared.locationsWith(query: query, filter: filter)
self.mapControl?.setFilter(locations: locations, behavior: .default)
if let location = locations?.first {
    self.mapControl?.currentFloor = location.floor
}
```

Please note that you are not guaranteed that the visible floor contains any search results, so that is why we change floor in the above example.
{% endtab %}

{% tab title="iOS v3" %}
Use the `MPLocationService` class to search for content in your MapsIndoors Solution.

**Setup a query for the nearest single best matching Location and display the result on the map**[**​**](https://docs.mapsindoors.com/search-on-map#setup-a-query-for-the-nearest-single-best-matching-location-and-display-the-result-on-the-map-2)

```swift
let filter = MPFilter()
let query = MPQuery()
query.query = "Office"
query.near = MPPoint(lat: 57.057964, lon: 9.9504112)
query.take = 1
MPLocationService.sharedInstance().getLocationsUsing(query, filter: filter) { (locations, error) in
    if error == nil {
        let location = locations?.first
        self.mapControl?.go(to: location)
    }
}
```

**Setup a query for a group of Locations and display the result on the map**[**​**](https://docs.mapsindoors.com/search-on-map#setup-a-query-for-a-group-of-locations-and-display-the-result-on-the-map-2)

```swift
let filter = MPFilter()
let query = MPQuery()
query.categories = ["Office"]
query.max = 50
MPLocationService.sharedInstance().getLocationsUsing(query, filter: filter) { (locations, error) in
    if error == nil {
        self.mapControl?.searchResult = locations
        let firstLocation = locations?.first
        self.mapControl?.currentFloor = firstLocation.floor
    }
}
```

Please note that you are not guaranteed that the visible floor contains any search results, so that is why we change floor in the above example.
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mapsindoors.com/sdks-and-frameworks/ios/searching/searching-on-a-map.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
