Load spots - xamoom/xamoom-ios-sdk GitHub Wiki

In this guide you will learn about all the different ways of loading spots like getting a spot with a given id, by tags, by location or name. All following calls are defined in XMMEnduserApi.

Spot by id

There are is one way to load one specific spot from our backend and that is by Id.

api.spot(withID: "spotId", completion: { (spot, error) in
   if let error = error {
      print("Error: \(error)")
   } else if let spot = spot {
      print("Spot: \(spot)")
   }
})

Query Spots

The SDK also implements calls for loading a list of spots. The result of these calls includes an array of XMMSpot, a bool flag "hasMore", a String "cursor" and an Error. All of these fields are also optional and can be null.

Sort

You can define the ordering, ascending or decending. You can also specify the attribute that should be used to sort the list. All available sorting options are listed in XMMOptions.

Radius

This will limit the result to spots within the given radius (meters) around a location. This only works if you also specify the center location in the query.

Options

This is used to define if you also want to include the markers or content in the result and also if you want spots with a physical location only. See -> XMMSpotOption.

Spots with tags

One of the most common ways to load a spot array is with tags. A popular use case is to load and show all spots for a specific topic, like landmarks.

api.spots(withTags:["landmark"], options: [], sort: .init(rawValue: 0), completion: { (spots, hasMore, cursor, error) in
   if let error = error {
      print("Error: \(error)")
   } else if let spots = spots {
      print("Spot count: \(spots.count)")
   }
})

Spots with location

Another way to load spots is around a location. For this you need the location as CLLocation and set a specific radius.

api.spots(with: userLocation, radius: 100, options: [] , sort: .init(rawValue: 0), completion: { (spots, hasMore, cursor, error) in
   if let error = error {
      print("Error: \(error)")
   } else if let spots = spots {
      print("Spot count: \(spots.count)")
   }
})

Spots with name

You can also load spots with a String as part of their name. So if you have one or more spot names containing this name, you are using this kind of call.

api.spots(withName: "Klagenfurt", pageSize: 100, cursor: nil, options: [], sort: .init(rawValue: 0), completion: { (spots, hasMore, cursor, error) in
   if let error = error {
      print("Error: \(error)")
   } else if let spots = spots {
      print("Spot count: \(spots.count)")
   }
})

Next Step

Related sources