ionic3 - 如何在离子 3 中的 leaflet.map("map").setView 中使用当前纬度
问题描述
this.map = leaflet.map("map").setView([this.latitude, this.longitude], 10);
还使用此代码获取当前纬度
this.geolocation.getCurrentPosition().then( pos =>{
this.latitude = pos.coords.latitude;
this.longitude = pos.coords.longitude;
}).catch(err => console.log(err));
但它不会在真实设备中第一次渲染。
解决方案
你在打电话吗
this.map = leaflet.map("map").setView([this.latitude, this.longitude], 10);
在地理定位解决设备坐标之前?
设备可能需要一些时间来解决其位置。如果您设置视图并过早渲染地图,那么这可能解释了为什么您在第一次加载时遇到问题。
在 .then 方法中设置传单地图的视图可以解决您的问题。但是,您可能需要处理较长的解析时间,尤其是当地图是您的应用程序的关键组件时。IE,您不希望您的用户在加载地图时查看空白屏幕。
推荐阅读
- kotlin - 扩展函数的主变量约定
- java - 在 Hadoop 3.1.4 上运行 TestDFSIO 时出现 NoClassDefFoundException
- flutter - Flutter - 在 Android 上访问隐藏方法 Lsun/misc/Unsafe 错误
- c# - 如何使运动独立于物体的旋转?C# 统一
- java - 如何防止随机数重叠
- reactjs - 在选择为基于API调用时,设置SELECT的默认值
- java - Selenium - TestNG - 如何根据 Maven 命令行在并行使用中传递的参数跳过/禁用一些测试
- r - 使用 if-else [R] 添加具有条件值的新列
- odoo-13 - 将任何移动应用程序连接到 odoo 后端应用程序
- angular - Angular style.display 无法按预期工作