User Location

The Magnet Max SDK provides an easy way for developers to upload user locations to Max location service. Developers can also retrieve a user's last-known location or location history from the Magnet Max service.

Update User Location

The current user location can be updated to Max service in real time or in batch mode.

  • To update the current user location in real time:

    let location = MMDeviceLocation(longitude:lng, latitude:lat) // Get location info from current device // update location to MAX location service MMUser.currentUser()!.updateLocation(location!, success: {() in //Success }, failure: { (error) in //Failure })

  • To upload user location changes in batch mode, see the example below. This is useful for tracking user location history:

    var locations:[MMDeviceLocation] = [] // collecting device location updates in local list locations.append(...) // upload batch locations to MAX service MMUser.currentUser()!.saveLocations(locations, success: {() in //Success }, failure: { (error) in //Failure })

Retrieve User Location

You can also retrieve both the last-known location of specified users, or get a user's location history.

  • To get the last-known location of specified users:

    var users:[MMUser] = [] users.appdend(...) MMUser.lastKnownLocations(users, needsForceUpdate: true, success: {(locations) in //Success }, failure: { (error) in //Failure })

  • To get a user's location history, refer to the code example below.

    var user: MMUser = ... MMUser.locationHistory(user, success: {(history) in //Success }, failure: { (error) in //Failure })