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:

1
2
3
4
5
Max.Device.updateDeviceLocation().success(function() {
// do something on success
}).error(function(err) {
// handle error on failure
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

1
2
3
4
5
6
7
8
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
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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:

1
2
3
4
5
6
7
8
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
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

1
2
3
4
5
6
var userId = ...;
Max.Device.getDeviceLocationHistory(userId).success(function(history) {
// do something with user's history
}).error(function(err) {
// handle error on failure
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX