Repository navigation
Location Sharing Android
This article describes how to implement location sharing using the Android SDK.
Location sharing lets users share their location with each other.
Location Sharing requires a blue dot subscription.

If you haven’t already done so, you’ll need to generate a valid token in the Editor. To generate one, in the sidebar menu click Permissions, and then click Application Tokens. Click Add Application + to generate a token for your app. You can name it anything.
When configuring the Meridian SDK, set the application token you generated in the Editor:
LocationSharing.init("kd84hf83ck93k39dyi3nxo3mf94");For best results, call init from your Application class.
LocationSharing is the main access point to the Location Sharing API. Use the User, Friend, Invite, and Location classes to get the Location Sharing data.
// Creates a location sharing user. All users require a first name. Last name is optional.
User sampleUser = new User();
sampleUser.setFirstName("Sample User");
LocationSharing.shared().createUser(sampleUser, new LocationSharing.Callback() {
@Override
public void onSuccess(User user) {
// ...
}
@Override
public void onError(LocationSharingException t) {
// ...
}
}); LocationSharing.shared().startPostingLocationUpdates(applicationContext); LocationSharing.shared().stopPostingLocationUpdates(applicationContext); LocationSharing.shared().isUploadingServiceRunning()
// example: button that performs start and stop sharing location
if (LocationSharing.shared().isUploadingServiceRunning()) {
LocationSharing.shared().stopPostingLocationUpdates(applicationContext);
} else {
LocationSharing.shared().startPostingLocationUpdates(applicationContext);
} LocationSharing.shared().addListener(new LocationSharing.Listener() {
@Override
public void onPostingLocationUpdatesStarted() {
// ...
}
@Override
public void onFriendsUpdated(List friends) {
// ...
}
@Override
public void onPostingLocationUpdatesStopped() {
// ...
}
});Invitations expire after 7 days.
LocationSharing.shared().createInvite(new LocationSharing.Callback() {
@Override
public void onSuccess(Invite invite) {
// ...
// At this point, you can share the invite url. (invite.getShareUrl())
}
@Override
public void onError(LocationSharingException e) {
// ...
}
}); LocationSharing.shared().getFriends(new LocationSharing.Callback() {
@Override
public void onSuccess(List friendsList) {
// ...
}
@Override
public void onError(LocationSharingException e) {
// ...
}
});LocationSharing keeps a copy of the current user, for use by calls like createInvite and getFriends. The implementor is responsible for storing the current user and setting it to the LocationSharing object.
When an account is created, the new user is automatically set to the current user.
After creating the new user, store it:
LocationSharing.shared().createUser(newUser, new LocationSharing.Callback() {
@Override
public void onSuccess(User user) {
OurOwnStorage.save(newUser);
}
@Override
public void onError(LocationSharingException t) {
// ...
}
});If a user restarts the app, the current user needs to be set again. This is equivalent to a login operation.
LocationSharing.shared().setCurrentUser(OurOwnStorage.retrieveLocationSharingUser());