We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

class (SpatialRelationUtil)

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+Wearable5.1.0(18)+

Modules to Import

import { map, mapCommon } from '@kit.MapKit';

SpatialRelationUtil

Utility class for calculating point-surface relationships.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.Map.Core

Since: 5.0.0(12)

isPointContainedInPolygon

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+Wearable5.1.0(18)+

static isPointContainedInPolygon(points: Array<mapCommon.LatLng>, point: mapCommon.LatLng): boolean

Checks whether a point is within a polygon.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.Map.Core

Since: 5.0.0(12)

Parameters:

Expand
Name Type Mandatory Description
points Array<mapCommon.LatLng> Yes Coordinates of a polygon.
point mapCommon.LatLng Yes Coordinates of the point to be checked.

Returns:

Expand
Type Description
boolean

Indicates whether the point is within the polygon.

- true: yes

- false: no

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Expand
ID Error Message
401 Invalid input parameter.

Example:

let points: Array<mapCommon.LatLng> = [
  {
    latitude: 31.693478,
    longitude: 118.434595
  }, {
    latitude: 31.693478,
    longitude: 118.534595
  }, {
    latitude: 32.993478,
    longitude: 118.734595
  }, {
    latitude: 32.993478,
    longitude: 118.934595
  }
];
let point: mapCommon.LatLng = {
  latitude: 31.984,
  longitude: 118.766
};
let result: boolean = map.SpatialRelationUtil.isPointContainedInPolygon(points, point);