MapContext.translateMarker
Move the marker in the map. If you need to move the same marker on the map multiple times, must call the translateMarker function again after the animationEnd (the animation end callback function) of the previous marker movement occurs.
Parameters
Property | Type | Required | Description |
markerId | Number | Yes | The ID to specify a unique marker. |
destination | Object | Yes | Move the specified marker to the destination point. Example: copy
|
autoRotate | Boolean | No | Whether the marker automatically rotates during the movement. Default value: true |
rotate | Number | No | The rotation angle of the marker. Default value: 0 |
duration | Number | No | The duration of the animation in milliseconds. Default value: 1000 |
animationEnd | Function | No | The animation end callback function |
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). |
Sample code
Page({
data: {
longitude: 113.324520,
latitude: 23.099994,
markers: [{
id: 0,
longitude: 113.324520,
latitude: 23.099994,
iconPath: '/resource/ke.png', // cannot a relative path, only be an absolute path beginning with /
width: 30,
height: 30
}],
scale: 14,
mapCtx: null
},
onReady() {
this.data.mapCtx = my.createMapContext('map');
},
translateMarker() {
this.data.mapCtx.translateMarker({
markerId: 0,
destination: {
latitude: 23.100000,
longitude: 113.325000
},
duration: 1000, //The duration of the animation in milliseconds.
autoRotate: true, // Whether the marker automatically rotates
animationEnd: () => {
console.log('animation end');
}, // The animation end callback function
success: (res) => {
console.log(res);
},
fail: (error) => {
console.log(error);
}
});
}
});