react native 中使用 expo-location 获取位置信息时,按照官方文档执行案例,获取不到位置结果。Location.requestForegroundPermissionsAsync() 执行后可以获取授权状态,但是执行到 Location.getCurrentPositionAsync() 时不会打印结果。 解决方法: 给Location.getCurrentPositionAsync() 添加参数,如下 let location = await Loc...
[未处理的promise拒绝:错误:请求失败,状态码为400]在node_modules/axios/lib/core/createError. js:15:17 in createError atnode_modules/axios/lib/core/settel.js:16:9 in setleLoad atnode_modules/react-native/Library/Network/XMLHttpRequest.js:601:4 in setReadyState atnode_modules/react-native/Libr...
我也得到了确切的错误。
调用Geolocation.getCurrentPosition() 时,react-native-geolocation-service(^5.3.1) 会引发此错误或应用程序崩溃。添加react-native-maps(^1.8.0) 库后,错误开始出现。之前工作得很好。经过大量搜索后,我在某个地方看到这可能是由于其他模块的播放服务版本不匹配造成的。
即使在你的应用程序中已授予了位置权限,如果设备上没有打开位置服务,getCurrentPositionAsync()方法仍将返回一个空值。在这种情况下,你应该提示用户打开设备的位置服务。以下是一个示例代码: import { Alert, Linking } from 'react-native'; function openLocationSettings() { ...
This example will get the Current Location Latitude and Longitude of the Device. This example will also show you how to ask for permission to get the current location. So let’s get started. To Make a React Native App Getting started with React Nativewill help you to know more about the...
@expo/webpack-config: ^0.12.16 => 0.12.37 expo: ^39.0.3 => 39.0.3 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-39.0.3.tar.gz => 0.63.2 react-native-web: ~0.13.14 => 0.13.14 npmGlobalPackages: ...
你可以使用承诺来实现你想要做的事情。下面的代码应该可以工作并返回结果:
log(location); } getLocation(); 复制 getCurrentPositionAsync() 方法默认返回最近获取到的设备位置信息。我们可以传递空对象作为参数来使用默认选项,或者传递选项以获取更精细的位置信息。 结论 通过安装 expo-location 库并适当的添加 polyfill,我们可以在 React Native 应用程序中方便地获取设备的位置信息。在某些...
Installation in bare React Native projects For bare React Native projects, you must ensure that you haveinstalled and configured theexpopackagebefore continuing. Add the package to your npm dependencies npx expo install expo-get-location Configure for iOS ...