Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create location message

Create a location message with descriptive text and geographic coordinates.

Copy

The SDK embeds provided location descriptions and coordinates into the message payload without performing geolocation, reverse geocoding, or map rendering.

Code example

import sdk, { CreateLocationMessageReq, CreateLocationMessageResp } from '@openimsdk/imsdk';

const request: CreateLocationMessageReq = {
  description: 'Shenzhen Bay Park',
  longitude: 113.9516,
  latitude: 22.4864,
};
const response: CreateLocationMessageResp = await sdk.createLocationMessage(request);
const message = response.message;

Parameters

ParameterTypeRequiredDescription
descriptionstringYesHuman-readable address or landmark name.
longitudenumberYesLongitude coordinate (-180 to 180).
latitudenumberYesLatitude coordinate (-90 to 90).

Return value

Returns a Promise resolving to CreateLocationMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated location message object.

State changes after the call

Longitude must range between -180 and 180, and latitude must range between -90 and 90. Ensure coordinates use a consistent spatial reference frame (such as WGS-84 or GCJ-02). This operation only instantiates the IMMessage object locally; call Send message to dispatch it.