MapContext.mapToScreen

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

Parameters

Property

Type

Required

Description

latitude

Number

Yes

The map latitude.

longitude

Number

Yes

The map longitude.

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

x

Number

The corresponding X-coordinate on the screen.

y

Number

The corresponding Y-coordinate on the screen.

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: ""
    },
    onReady() {
        this.data.mapCtx = my.createMapContext('map');
    },
    mapToScreen() {
        this.data.mapCtx.mapToScreen({
            latitude: 30.202041,
            longitude: 120.108257,
            success: res => {
                console.log('success', res);
            },
            fail: error => {
                console.log('fail', error);
            }
        });
    }
});