【发布时间】:2024-01-08 00:37:01
【问题描述】:
我想在 react-native 中添加位置。我在 react-native 中有一个简单的应用程序。我想添加使用该应用程序的用户的地理位置。想法是在 Laravel 的管理面板上显示移动用户的当前位置。移动应用程序将在 laravel 中的 react-native 和 web 上。我正在寻找如何做到这一点的指南。
【问题讨论】:
标签: javascript react-native geolocation
我想在 react-native 中添加位置。我在 react-native 中有一个简单的应用程序。我想添加使用该应用程序的用户的地理位置。想法是在 Laravel 的管理面板上显示移动用户的当前位置。移动应用程序将在 laravel 中的 react-native 和 web 上。我正在寻找如何做到这一点的指南。
【问题讨论】:
标签: javascript react-native geolocation
您可以为此使用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 }
);
}
}
希望这对你有用。
【讨论】: