版权声明:本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出 原文链接 如有问题, 可发送邮件咨询. https://blog.csdn.net/weixin_37865166/article/details/89202568
原文地址: https://dsx2016.com/?p=400
➢ github
项目: react-native-amap-geolocation
这里只需要定位需求,有人写好了,可以直接食用
项目地址: https://github.com/qiuxiang/react-native-amap-geolocation
➢ android
安装
下载依赖包
npm i react-native-amap-geolocation
link
原生
react-native link react-native-amap-geolocation
➢ 获取高德Key
参考文章: https://dsx2016.com/?p=397
➢ 使用方式
注意github
上的文档,如有语法错误,注意添加async
import { PermissionsAndroid } from "react-native"
import { Geolocation } from "react-native-amap-geolocation"
let getGps = async () => {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
await Geolocation.init({
ios: "高德key",
android: "高德key"
});
Geolocation.setOptions({
interval: 3000,
distanceFilter: 20
});
Geolocation.addLocationListener(location => {
console.log(location, numTime++);
let gpsData = { ...location };
gpsData.userName = `大师兄`;
insertGps(gpsData);
});
Geolocation.start();
}
};
getGps();