小编Vla*_*sov的帖子

expo-location (React-Native) :Location.getCurrentPositionAsync() 永远不会返回任何内容

我正在开发一个跨平台的移动应用程序。

我正在 Android Studio 模拟器(google Pixel 5,api 级别 30)上测试我的代码,我使用的是 expo 版本:~43.0.2 和 expo-location 版本:~13.0.4

我已经请求了位置许可,并且它有效。但是当我调用以下代码时,我会记录“那里”,但不会记录“这里”:

        console.log("there")
        const userLocation = await Location.getCurrentPositionAsync()
        console.log("here")
Run Code Online (Sandbox Code Playgroud)

事实上,函数 Location.getCurrentPositionAsync() 似乎被锁定

根据以下链接,过去已经知道类似的问题:

React Native Expo-Location 返回位置服务在初始 useEffect 期间不可用 https://forums.expo.dev/t/getcurrentpositionasync-doesnt-return-any-value-infinity-loading/23643

但这也是 Expo 文档中的代码:

https://snack.expo.dev/@charliecruzan/expo-map-and-location-example

。下面是整个应用程序类:


import { StatusBar } from 'expo-status-bar';
import React from 'react';
import {Text, TextInput, Pressable, View, Alert} from 'react-native';
import * as Location from "expo-location"


export default class App extends React.Component{
    state = {
        errorMessage: "",
        location: {}
    }

    getAddress(){
        return this.state.address
    } …
Run Code Online (Sandbox Code Playgroud)

react-native expo

9
推荐指数
1
解决办法
8839
查看次数

标签 统计

expo ×1

react-native ×1