How geolocation.getCurrentPosition return value?(geolocation.getCurrentPosition 如何返回值?)
问题描述
我正在使用 getCurrentPosition 来获取当地的纬度和经度.我知道这个函数是异步的,只是想知道如何返回其他函数可以访问的经纬度值?
I am using getCurrentPosition to get local latitude and longitude. I know this function is asynchronous, just wondering how to return latitude and longitude value that can be accessed by other functions?
推荐答案
我建议你把它包装在一个承诺中:
I would suggest you wrapping it in a promise:
https://jsfiddle.net/DerekL/zr8L57sL/
ES6 版本:
https://jsfiddle.net/DerekL/90129LoL/
这篇关于geolocation.getCurrentPosition 如何返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!