提问人:Praveen Dhayalan 提问时间:7/15/2023 更新时间:7/15/2023 访问量:242
我怎样才能请求在用户的iPhone上访问我们的精确位置的权限?在 React Native 中
How can I request permission to access our precise location on the user's iPhone? in React Native
问:
向 #ReactNative 开发人员寻求指导:如何在 iPhone 上请求精确位置权限?需要帮助在我的应用程序中实现。提示和代码示例不胜感激!谢谢!#LocationPermission
参考任何软件包或提出任何想法。
答:
0赞
Beom
7/15/2023
#1
要在 React Native 中获取位置,您可以使用 react-native-geolocation-service。
您可以使用以下代码获取位置。
Geolocation.getCurrentPosition(
position => {
const {latitude, longitude} = position.coords;
},
error => {
console.error(error.code, error.message);
},
{enableHighAccuracy: true, timeout: 15000, maximumAge: 10000},
);
但要使用上面的代码,您需要请求许可才能使用您的位置。
在 iOS 中,您可以通过以下代码获得使用位置的权限。
import Geolocation from 'react-native-geolocation-service';
Geolocation.requestAuthorization('always');
有关详细信息,请参阅:github
祝您编码愉快!
评论