Browse SDKs · Android
Platform
SDKsAndroid

Create a location message

Use createLocationMessage to create a message with coordinates and a location description.

Copy

Construct a location message object containing geographic coordinates (latitude and longitude) and a detailed textual address. This is typically used to share current location pins or place cards within a chat.

Code example

double latitude = 39.9042;
double longitude = 116.4074;
String description = "Tiananmen Square, Dongcheng District, Beijing";

Message message = OpenIMClient.getInstance().messageManager.createLocationMessage(
    latitude,
    longitude,
    description
);

Parameters

ParameterTypeRequiredDescription
latitudedoubleYesLatitude coordinate, valid from -90.0 to 90.0.
longitudedoubleYesLongitude coordinate, valid from -180.0 to 180.0.
descriptionStringYesPlace name or detailed textual address displayed to recipients.

Return value

Returns the created Message object with contentType set to MessageType.LOCATION.

State changes after the call

  1. Local initialization: Initializes the local Message structure without prompting for location permissions or sending data to the server.
  2. Transmission: Call Send a message to deliver the location message to a single user or group.