其他分享
首页 > 其他分享> > 高德地图定位(react-native-amap-geolocation)

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

作者:互联网

高德地图定位(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();   //获取最后一次定位的位置

标签:keystore,geolocation,node,react,amap,native
来源: https://blog.csdn.net/weixin_44666116/article/details/111032592