1. 程式人生 > 其它 >高德地圖定位(react-native-amap-geolocation)

高德地圖定位(react-native-amap-geolocation)

技術標籤:高德地圖react native定位react nativeandroid

高德地圖定位(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

img

呼叫

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();   //獲取最後一次定位的位置

個人部落格