It seems that you are trying to create the places object:
let places = NMAPlaces()
But places object is Singleton and can be retrieved only by calling shared()
let places = NMAPlaces.shared()
Also as you are using result?.start(listener: self)
method you need to implement the NMAResultListener listener. Example of simple listener:
class MainViewController: UIViewController, NMAResultListener {
func requestDidComplete(_ request: NMARequest, data: Any?, error inError: Error?) {
print("data = \(String(describing: data))")
guard inError == nil else {
print ("Request error \((inError! as NSError).code)")
return
}
guard data is NMADiscoveryPage, let resultPage = data as? NMADiscoveryPage else {
print ("invalid type returned \(String(describing: data))")
return
}
let resultsArray: [NMALink] = resultPage.discoveryResults;
for link in resultsArray
{
if let placeLink = link as? NMAPlaceLink {
print("PlaceLink position: \(placeLink.position.latitude), \(placeLink.position.longitude)")
}
}
}
....
}
====================================================================
Let's assume you are searching in UK, London(51.514545,-0.131666) and use NMAResultListener as described above. In both requests the listener parameter self
implements NMAResultListener as described above.
The code for makeSearchRequest might be next:
let geoCoordCenter = NMAGeoCoordinates(latitude:51.514545, longitude: -0.131666)
let searchRequest = NMAPlaces.shared().makeSearchRequest(location: geoCoordCenter, query: "restaurant")
searchRequest?.start(listener: self)
When request is finished the makeSearchRequest will return results:
data = Optional(<NMADiscoveryPage: 0x28241a400>)
PlaceLink position: 51.5117, -0.12565
PlaceLink position: 51.51312, -0.13374
....
PlaceLink position: 51.51371, -0.13155
PlaceLink position: 51.51462, -0.12651
And code for makeHereRequest:
let geoCoordCenter = NMAGeoCoordinates(latitude:51.514545, longitude: -0.131666)
let hereRequest = NMAPlaces.shared().makeHereRequest(location: geoCoordCenter, filters: nil)
hereRequest?.start(listener: self)
makeHereRequest will return results:
data = Optional(<NMADiscoveryPage: 0x282400f00>)
PlaceLink position: 51.514542, -0.131883
PlaceLink position: 51.514542, -0.131883
....
PlaceLink position: 51.51435, -0.13169
PlaceLink position: 51.51444, -0.13194
PlaceLink position: 51.51444, -0.13194
Also note that depending on network conditions and the location of search there also might be error result like not found
or other errors.