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:

Max.Device.updateDeviceLocation().success(function() { // do something on success }).error(function(err) { // handle error on failure });

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

var locations = []; // collecting device location updates in local list locations.push(...); Max.Device.saveLocations(locations).success(function() { // do something on success }).error(function(err) { // handle error on 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 userIds = []; // collecting user IDs userIds.push(...); Max.Device.getDeviceLocation(userIds).success(function(locations) { // do something with list of locations }).error(function(err) { // handle error on failure });

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

var userId = ...; Max.Device.getDeviceLocationHistory(userId).success(function(history) { // do something with user's history }).error(function(err) { // handle error on failure });