User Location

The Magnet Max SDK provides an easy way for developers to upload user locations to the 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 to the Magnet Max service in real time:

MMDeviceLocation *location = [[MMDeviceLocation alloc] initWithLongitude:lng latitude:lat]; // Get location info from current device // update location to MAX location service [[MMUser currentUser] updateLocation:location success:^{ //Success } failure:^(NSError *error) { //Failure }];

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

NSMutableArray *locations = [[NSMutableArray alloc] init]; // collecting device location updates in local list [locations addObject: location]; // upload batch locations to MAX service [[MMUser currentUser] saveLocations:locations success:^{ //Success } failure:^(NSError *error) { //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:

NSMutableArray *users = [[NSMutableArray alloc] init]; [users addObject: user]; [MMUser lastKnownLocations:users needsForceUpdate:true success:^(NSArray<MMDeviceLocationInfo *> *locations){ //Success } failure:^(NSError *error) { //Failure }];

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

[MMUser locationHistory:user success:^(NSArray<MMDeviceLocation *> *history){ //Success } failure:^(NSError *error) { //Failure }];