Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
import { map, mapCommon } from '@kit.MapKit'; 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)
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:
| 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:
| 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.
| 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);