Source: https://developers.woosmap.com/products/geofencing-sdk/ios-sdk/guides/find-nearest-pois/

> For clean Markdown of any page, append `.md` to the page URL.

> For a complete documentation index, see https://developers.woosmap.com/llms.txt

# Find nearest POIs



## Use Stores API to find the Nearest POIs

You need a [Private API key](/api-reference/authentication/#registering-a-woosmap-private-api-key) to request the Woosmap Stores API.

In your `AppDelegate`, set keys, and set a delegate to monitor result of the Search API request :

```swift
let dataPOI = DataPOI()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        // Set Woosmap API Private key
        WoosmapGeofenceManager.shared.setWoosmapAPIKey(key: WoosmapKey)

         // Set delegate of protocol POI
        WoosmapGeofenceManager.shared.getLocationService().searchAPIDataDelegate = DataPOI()

        return true
}
```

To send request to the Search API, you can perform on demand requests to the Search API by using the following method:

```swift
let location = CLLocation(latitude: latitude, longitude: longitude)
WoosmapGeofenceManager.shared.getLocationService().sendSearchAPIRequest(location: location)
```

### Search API Delegate

Get the result of the Search API request in your class delegate `DataPOI` :

```swift
public class DataPOI:SearchAPIDelegate  {
    public init() {}

    public func searchAPIResponse(poi: POI) {
        NotificationCenter.default.post(name: .newPOISaved, object: self, userInfo: ["POI": poi])
    }

    public func searchAPIError(error: String) {

    }

    public func readPOI()-> [POI] {
        return POIs.getAll()
    }

    func getPOIbyLocationID(locationId: String)-> POI? {
        return POIs.getPOIbyLocationID(locationId: locationId)
    }

    public func erasePOI() {
        POIs.deleteAll()
    }

}

```

More details about the [Woosmap Stores API](/products/stores-api/overview/)

### Request Parameters

Set parameter to narrow your results or filters it with the `query` parameter.
More details in the [Woosmap Stores API documentation](/products/stores-api/overview/):

```swift
WoosmapGeofenceManager.shared.setSearchAPIParameters(parameters: ["radius":"20000","stores_by_page":"2", "query":"type:\"click&collect\""])
```

## Use a Distance provider to retrieve distance and duration value

As for the Search API, request to the Distance provider can be done on demand (e.g. if not enabled with each location collection or if needed on dedicated process of your own). To retrieve distance and duration values between origin(s) and destination(s), you must create a class delegate to retrieve the those data when the method `distanceAPIRequest`is called.

In your `AppDelegate`, set keys, and set a delegate to monitor result of the Woosmap Distance API request :

```swift
let dataDistance = DataDistance()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

         // Set delegate of protocol Distance
        WoosmapGeofenceManager.shared.getLocationService().distanceAPIDataDelegate = DataDistance()

        // [...]

        return true
}
```

### Distance Delegate

Get the result of the Distance provider API request in your class delegate `DataDistance` :

```swift
public class DataDistance:DistanceAPIDelegate  {
    public init() {}

    public func distanceAPIError(error: String) {
        print(error)
    }

    public func distanceAPIResponse(distance: [Distance]) {
        print("distance = " + distance.debugDescription)

    }

}
```

### Send request to retrieve distance and duration data

As for the Search API, if you need to trigger distance requests (to calculate distance and duration) by your own, you can perform on demand requests to the Distance API. Parameters are optional, if not defined, tracking profile values are used as default value.

```swift
WoosmapGeofenceManager.shared.getLocationService().calculateDistance(
    // set latitude and longitude of the origin
    locationOrigin: location,

    // set the latitude and longitude of destinations,
    coordinatesDest: destinations,

    // [OPTIONAL] enable/disable traffic data
    distanceWithTraffic: false,

    // [OPTIONAL] change the travel mode ("walking", "cycling" or "driving")
    distanceMode: DistanceMode.walking,

    // [OPTIONAL] change the distance units ("imperial" or "metric")
    distanceUnits: DistanceUnits.imperial,

    // [OPTIONAL] change the language for textual result (example: "en", "fr")
    distanceLanguage: "en"
)
```

More details about the [Woosmap Distance API](/products/distance-api/overview/)
