javascript - 地理位置真的很慢我做错了什么?
问题描述
我尝试从浏览器获取位置,但从 5 秒到 8 秒真的很慢。不知道为什么这么慢
const getUserGeolocation = (): Promise<{latitude: number, longitude: number}> => new Promise(async (resolve) => {
navigator.geolocation.getCurrentPosition(async pos => {
resolve({latitude: pos.coords.latitude, longitude: pos.coords.longitude})
})
})
const {latitude, longitude} = await getUserGeolocation()
解决方案
可能只是因为使用了太多async。从代码中删除两个 async 关键字。我认为这将帮助您更快地执行代码。
推荐阅读
- node.js - 如何在nodejs中'couchbase db中的连接池'?
- elixir - 如何将字符串评估为变量
- javascript - 我可以创建一个对象 selreference 方法吗,当我这样做等于另一个变量时
- javascript - 我如何向这个计数脚本添加一个短时间延迟?(这样当用户真正看到它时它就会开始计数,可能会延迟 4-5 秒)
- angular - 在 ngOnInit 之后调用 ngOnDestroy
- android - 如何在键盘布局中使用 ViewStub
- themes - PrestaShop 1.6 - 无法覆盖主题中的模块 tpl 文件
- wordpress - WordPress,我们如何获取浏览器网络监控中显示的所有js和css文件
- mattermost - 为用户添加短文本/徽章/图标
- aws-sam - 原因:无效的模板属性或属性 [Api]