Find nearest POIs

Find nearest POIs using iOS SDK

  1. Use Search API to find the Nearest POIs
  2. Use a Distance provider to retrieve distance and duration value

Use Search API to find the Nearest POIs

You need a Private API key to request the Woosmap Search 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 delagate 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 Search API

Request Parameters

Set parameter to narrow your results or filters it with the query parameter. More details in the Woosmap Search API documentation:

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 distanceAPIRequestis 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

Was this article helpful?
Have more questions? Submit a request