React Native 高德地图定位模块,支持 Android + iOS。
import { PermissionsAndroid } from "react-native"
import { Geolocation } from "react-native-amap-geolocation"
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
await Geolocation.init({
ios: "9bd6c82e77583020a73ef1af59d0c759",
android: "043b24fe18785f33c491705ffe5b6935"
})
Geolocation.setOptions({
interval: 8000,
distanceFilter: 20
})
Geolocation.addLocationListener(location => console.log(location))
Geolocation.start()
}
你可以直接下载安装 example.apk,或者按照以下步骤运行项目示例:
yarn
# android
yarn run-android
# ios
cd ios && pod install && cd ..
yarn run-ios