解决方法
new
多个Geocoder
,然后不同的点用不同的回调函数;适用于标记点不多的情况,多点标记不适用。- 用setTimeout;但是多点渲染使用该方法很不现实,
- 把
Geocoder
及其回调函数放到for循环中,该方法适用于多点标记,具体如下。
for (let index = 0; index < 2; index++) {
const geocoder = new qq.maps.Geocoder();
geocoder.setComplete(result => {
this.completeCallback(result);
});
if (index === 0) {
geocoder.getAddress(path[0]);
} else {
geocoder.getAddress(path[lastIndex]);
}
}
这里把回调函数的function转换成箭头函数了。
completeCallback(result) {
console.log(result);
const start = new qq.maps.Label({
position: result.detail.location,
map: this.map,
content: result.detail.address
});
const marker = new qq.maps.Marker({
map: this.map,
position: result.detail.location
});
}
结尾
我是圆圆,如果我的文章对你的学习成长有所帮助,欢迎 点 赞 👍 支持,您的 点 赞 👍 支持是我进行创作和分享的动力!
如果有问题可以留言评论或者私信我,我都会一一解答~笔芯🤞