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 Max service in real time:

DeviceLocation location = new DeviceLocation.DeviceLocationBuilder() .lastKnownDate(new Date()) .longitude(longitude) .latitude(latitude) .build(); // update location to Max service User.updateLocation(location, new ApiCallback<Boolean>() { @Override public void success(Boolean aBoolean) { //Success } @Override public void failure(ApiError error) { //Failure } });

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

ArrayList<DeviceLocation> locationsList = new ArrayList<>(); // collecting device location updates in local list locationsList.add(...); // upload batch locations to MAX service User.uploadBatchLocations(locationsList, new ApiCallback<Boolean>() { @Override public void success(Boolean aBoolean) { //Success } @Override public void failure(ApiError 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:

List<String> userIDs = new ArrayList<>(); userIDs.add(...); // Get users last-known location from Max service User.getLastKnownLocations(userIDs, true, new ApiCallback<List<DeviceLocationInfo>>() { @Override public void success(List<DeviceLocationInfo> locationInfos) { //Success } @Override public void failure(ApiError error) { //Failure } });

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

User.getLocationHistory(userID, new ApiCallback<List<DeviceLocationInfo>>() { @Override public void success(List<DeviceLocationInfo> locationInfos) { //Success } @Override public void failure(ApiError error) { //Failure } });