javascript - react-native 如何定位移动应用的用户?
问题描述
我想在 react-native 中添加位置。我在 react-native 中有一个简单的应用程序。我想添加使用该应用程序的用户的地理位置。想法是在 Laravel 的管理面板上显示移动用户的当前位置。移动应用程序将在 laravel 中的 react-native 和 web 上。我正在寻找指导如何做到这一点。
解决方案
您可以为此使用react-native-geolocation-service库。
使用此 cmd 安装库npm install react-native-geolocation-service
并像这样实现它:
...
import Geolocation from 'react-native-geolocation-service';
...
componentDidMount() {
if (hasLocationPermission) {
Geolocation.getCurrentPosition(
(position) => {
//here you'll get your current location
console.log(position);
},
(error) => {
// See error code charts below.
console.log(error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
);
}
}
希望这对你有用。
推荐阅读
- firebase - 将firebase导出到azure sql的最佳方法
- mysql - 为什么选择 1 失败时返回 1
- mongodb - MongoDB- 按 id 查找文档,然后用键对其进行分组
- qt - QtCreator 5.0.0 - 将区域的背景颜色设置为编辑器边距
- python-3.x - tensorflow 2.0卷积层中的自定义填充
- php - 如何存储和检索数据以供 HTML 表单使用?
- javascript - 如何使用 localstorage 在我的网页上使用 JavaScript 显示值?
- sql-server - Powershell 数据读取器返回不需要的文本
- performance - 如何将 Prolog 的剪辑转换为 Curry?
- docker - 你如何与容器化 api 通信