-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ios getCurrentPosition 没有位置信息 #111
Comments
你解决了吗 |
已经解决了,谢谢
…------------------ 原始邮件 ------------------
发件人: "赵亚"<notifications@github.com>;
发送时间: 2020年3月30日(星期一) 下午2:32
收件人: "qiuxiang/react-native-amap-geolocation"<react-native-amap-geolocation@noreply.github.com>;
抄送: "呐呐呐呐呐呐"<2298692991@qq.com>; "Comment"<comment@noreply.github.com>;
主题: Re: [qiuxiang/react-native-amap-geolocation] ios getCurrentPosition 没有位置信息 (#111)
你解决了吗
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
我目前是通过持续定位获取的 /**
* 获取当前位置
*/
export async function getCurrentLocation() {
try {
// android 请求权限
if (IS_ANDROID) {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION)
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
return
}
}
// 初始化 sdk
await init({
ios: '',
android: ''
})
// 监听定位变化,监听到城市位置信息之后,resolve 并停止定位
const locationPromise = new Promise(resolve => {
setLocatingWithReGeocode(true)
setNeedAddress(true)
addLocationListener(location => {
if (location && location.adCode) {
resolve(location)
stop()
}
})
})
// 超时,20 秒之后直接 resolve
const timeoutPromise = new Promise(resolve => {
setTimeout(() => {
stop()
resolve()
}, 20 * 1000)
})
start()
return Promise.race([locationPromise, timeoutPromise])
} catch (err) {
console.warn(err)
}
} |
这句代码很关键 |
Geolocation.getCurrentPosition((data) => { 打印结果: |
android 可以正常获取,ios 则只有经纬度信息
The text was updated successfully, but these errors were encountered: