高德地圖定位(react-native-amap-geolocation)
定位位址: react-native-amap-geolocation
安裝
npm install --save react-native-amap-geolocation
android
react-native link react-native-amap-geolocation
ios
在ios目錄下建立
Podfile
platform :ios, '8.0'
# The target name is most likely the name of your project.
target 'Your Target' do
# Your 'node_modules' directory is probably in the root of your project,
# but if not, adjust the `:path` accordingly
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'CxxBridge', # Include this for RN >= 0.47
'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
'RCTText',
'RCTNetwork',
'RCTWebSocket', # Needed for debugging
'RCTAnimation', # Needed for FlatList and animations running on native UI thread
# Add any other subspecs you want to use in your project
]
# Explicitly include Yoga if you are using RN >= 0.42.0
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
# Third party deps podspec link
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'react-native-amap-geolocation', path: '../node_modules/react-native-amap-geolocation/lib/ios'
end
pod install
key
android
https://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key
釋出版keystore 生成方法
keystore參數文檔
測試版 keystore 自動生成
keystore 存放位址
路徑:項目\android\app
查詢keystore 的SHA1值
進入目前檔案夾中的 cmd
釋出版 keystore
keytool -v -list -keystore my-release-key.keystore
一定記住密鑰庫密碼
測試版 keystore
keytool -v -list -keystore debug.keystore
密碼:android
傳回 SHA1值 例圖如上
配置AndroidManifest.xml
android 配置
ios
需要填寫
Bundle Identifier

調用
import { Geolocation } from "react-native-amap-geolocation";
const geolocationInit = async () => {
await Geolocation.init({
ios: "key",
android: "key"
});
Geolocation.setOptions({
interval: 3000,
distanceFilter: 20
});
Geolocation.addLocationListener(location => {
console.log(location);
});
}
geolocationInit();
Geolocation.start(); //開始定位
Geolocation.stop(); //擷取到定位後需要手動關閉,持續定位ios稽核不過
Geolocation.getLastLocation(); //擷取最後一次定位的位置
個人部落格