MapContext.screenToMap

Convert screen coordinates to corresponding coordinates (latitude and longitude) on the map.

Parameters

Property

Type

Required

Description

X

Number

Yes

The X-coordinate on the screen.

Y

Number

Yes

The Y-coordinate on the screen.

success

Function

No

The callback function that is called upon successful call.

fail

Function

No

The callback function that is called upon failed call.

complete

Function

No

The callback function that is called upon call completion (to be executed upon either call success or failure).

success callback function

The parameters are in object type and have the following properties:

Property

Type

Description

latitude

Number

The corresponding latitude on the map.

longitude

Number

The corresponding longitude on the map.

fail callback function

The parameter of the fail callback function is an object, where:

  • error : indicates the error code
  • errorMessage : indicates the error message.

Error code

Error code

Error message

Further action

2

Invalid parameters. For example, the data type is incorrect.


Fill in the correct parameters per the Parameters section.

Sample code

copy
Page({
    data: {
        mapCtx: null,
    },
    onReady() {
        this.mapCtx = my.createMapContext("map");
    },
    screenToMap() {
        this.mapCtx.screenToMap({
            x: 0,
            y: 0,
            success: res => {
                console.log(res);
            },
            fail: error => {
                console.log(error)
            }
        });
    },
});