目录

Interface (Projection)

Modules to Import

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

Projection

Used for conversion between screen coordinates and longitude-latitude coordinates. An instance of this type will be returned when the getProjection method in the map.MapComponentController class is called.

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 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Example:

let projection: map.Projection = this.mapController?.getProjection();

[h2]fromScreenLocation

fromScreenLocation(point: mapCommon.MapPoint): mapCommon.LatLng

Converts screen pixel coordinates to longitude-latitude coordinates. The location on the screen is specified in screen pixels (instead of display pixels) relative to the top left corner of the map (instead of the top left corner of the screen).

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 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
point mapCommon.MapPoint Yes Coordinate point on the screen. Invalid values are not processed.

Returns:

Type Description
mapCommon.LatLng Longitude-latitude coordinates.

Example:

let point: mapCommon.MapPoint = {
  positionX: 10,
  positionY: 10
};
let latLng: mapCommon.LatLng = projection.fromScreenLocation(point);

[h2]fromScreenLocation

fromScreenLocation(point: mapCommon.MapPoint, altitude: number): mapCommon.LatLng

Converts screen pixel coordinates to longitude-latitude coordinates. A screen position is specified in screen pixels relative to the top-left corner of the map interface.

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

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Map.Core

Since: 26.0.0

Parameters:

Name Type Mandatory Description
point mapCommon.MapPoint Yes Coordinate point on the screen. Invalid values are not processed.
altitude number Yes Height relative to the ground, in meters. The default value is 0. If an invalid value is passed, the default value will be used.

Returns:

Type Description
mapCommon.LatLng Longitude-latitude coordinates.

Example:

let point: mapCommon.MapPoint = {
  positionX: 10,
  positionY: 10
};
let latLng: mapCommon.LatLng = projection.fromScreenLocation(point, 100);

[h2]toScreenLocation

toScreenLocation(position: mapCommon.LatLng): mapCommon.MapPoint

Converts longitude-latitude coordinates into the corresponding point coordinates on the screen. The screen coordinates are pixel coordinates relative to the top-left corner of the map, rather than the entire screen.

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 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Parameters:

Name Type Mandatory Description
position mapCommon.LatLng Yes Longitude-latitude coordinates. Invalid values are not processed.

Returns:

Type Description
mapCommon.MapPoint Coordinate point on the screen.

Example:

let position: mapCommon.LatLng = {
  latitude: 31.984,
  longitude: 118.766
}
let mapPoint: mapCommon.MapPoint = projection.toScreenLocation(position)

[h2]toScreenLocation

toScreenLocation(position: mapCommon.LatLng, altitude: number): mapCommon.MapPoint

Converts longitude-latitude coordinates into the corresponding point coordinates on the screen. The screen coordinates are pixel coordinates relative to the top-left corner of the map, rather than the entire screen.

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

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Map.Core

Since: 26.0.0

Parameters:

Name Type Mandatory Description
position mapCommon.LatLng Yes Longitude-latitude coordinates. Invalid values are not processed.
altitude number Yes Height relative to the ground, in meters. The default value is 0. If an invalid value is passed, the default value will be used.

Returns:

Type Description
mapCommon.MapPoint Coordinate point on the screen.

Example:

let position: mapCommon.LatLng = {
  latitude: 31.984,
  longitude: 118.766
}
let mapPoint: mapCommon.MapPoint = projection.toScreenLocation(position, 100)

[h2]getVisibleRegion

getVisibleRegion(): mapCommon.VisibleRegion

Obtains the coordinates of the visible region.

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 4.1.0(11).

System capability: SystemCapability.Map.Core

Since: 4.1.0(11)

Returns:

Type Description
mapCommon.VisibleRegion Visible region.

Example:

let visibleRegion: mapCommon.VisibleRegion = projection.getVisibleRegion();

[h2]getMapBounds

getMapBounds(center: mapCommon.LatLng, zoom: number): mapCommon.LatLngBounds

Obtains the destination region corresponding to the map control based on the center point and the zoom level of the map.

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
center mapCommon.LatLng Yes Longitude-latitude coordinates of the center point. Invalid values are not processed.
zoom number Yes Zoom level. The value ranges from 2 to 20. If the passed value is greater than the maximum zoom level, the maximum zoom level is used. If the passed value is less than the minimum zoom level, the minimum zoom level is used.

Returns:

Type Description
mapCommon.LatLngBounds Destination region.

Example:

let position: mapCommon.LatLng = {
  latitude: 31.98,
  longitude: 118.766
};
let result: mapCommon.LatLngBounds = projection.getMapBounds(position, 10);