react-native android app高德地图sdk定位

网易云课堂

视频地址: react native 从创建到发布

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();