Giter VIP home page Giter VIP logo

uiwjs / react-native-amap-geolocation Goto Github PK

View Code? Open in Web Editor NEW
42.0 6.0 5.0 8.12 MB

React Native 高德地图定位模块,支持 Android/iOS。

Home Page: https://uiwjs.github.io/react-native-amap-geolocation/

License: MIT License

Java 41.02% JavaScript 21.01% Ruby 5.01% Objective-C 21.62% TypeScript 9.64% Objective-C++ 1.69%
amap react-native react amapsdk amap-app react-native-component android ios react-amap geolocation

react-native-amap-geolocation's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency prettier to v2.8.8
  • chore(deps): update dependency @types/react-test-renderer to v18.3.0
  • chore(deps): update dependency cocoapods to v1.15.2
  • chore(deps): update dependency eslint to v8.57.1
  • chore(deps): update dependency react-native to v0.75.3
  • chore(deps): update react monorepo (@types/react, react, react-test-renderer)
  • fix(deps): update dependency com.amap.api:location to v6.4.7
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency @tsconfig/react-native to v3
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency node to v20
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency ruby to v3
  • chore(deps): update dependency typescript to v5
  • chore(deps): update peaceiris/actions-gh-pages action to v4
  • fix(deps): update dependency com.android.tools.build:gradle to v8
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

bundler
example/Gemfile
  • cocoapods '~> 1.11', '>= 1.11.3'
cocoapods
example/ios/Podfile
github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
  • peaceiris/actions-gh-pages v3
  • ncipollo/release-action v1
gradle
android/build.gradle
  • com.amap.api:location 6.2.0
example/android/gradle.properties
  • com.facebook.flipper:flipper 0.125.0
  • com.facebook.flipper:flipper-network-plugin 0.125.0
  • com.facebook.flipper:flipper-fresco-plugin 0.125.0
example/android/settings.gradle
example/android/build.gradle
  • com.android.tools.build:gradle 7.3.1
example/android/app/build.gradle
  • androidx.swiperefreshlayout:swiperefreshlayout 1.0.0
gradle-wrapper
example/android/gradle/wrapper/gradle-wrapper.properties
  • gradle 7.5.1
nodenv
example/.node-version
  • node 18
npm
example/package.json
  • react 18.2.0
  • react-native 0.71.4
  • @babel/core ^7.20.0
  • @babel/preset-env ^7.20.0
  • @babel/runtime ^7.20.0
  • @react-native-community/eslint-config ^3.2.0
  • @tsconfig/react-native ^2.0.2
  • @types/jest ^29.2.1
  • @types/react ^18.0.24
  • @types/react-test-renderer ^18.0.0
  • babel-jest ^29.2.1
  • eslint ^8.19.0
  • jest ^29.2.1
  • metro-react-native-babel-preset 0.73.8
  • prettier ^2.4.1
  • react-test-renderer 18.2.0
  • typescript 4.8.4
package.json
  • react 18.2.0
  • react-native 0.71.4
  • typedoc 0.18.0
  • typescript 4.8.4
  • react ^16.8.1
  • react-native >=0.60.0-rc.0 <1.0.x
ruby-version
example/.ruby-version
  • ruby 2.7.6

  • Check this box to trigger a request for Renovate to run again on this repository

你好,我android按照如下配置后老式返回null,无法定位

import { Platform } from 'react-native';
import AMapGeolocation from '@uiw/react-native-amap-geolocation';

let apiKey = '';

if (Platform.OS === 'ios') {
  apiKey = '用于 iOS 的 apiKey';
}
if (Platform.OS === 'android') {
  apiKey = '用于 Android 的 apiKey';
}

// 设置 高德地图 apiKey
AMapGeolocation.setApiKey(apiKey);
// iOS 指定所需的精度级别
AMapGeolocation.setDesiredAccuracy(3);
// Android 指定所需的精度级别,可选设置,默认 高精度定位模式
AMapGeolocation.setLocationMode(1);
// 定位是否返回逆地理信息
AMapGeolocation.setLocatingWithReGeocode(true);

async function getCurrentLocation(){
  try {
    const json = await AMapGeolocation.getCurrentLocation();
    console.log('json:', json);
  } catch (error) {
    console.log('error:', error);
  }
}

getCurrentLocation的json 老是null,请问要如何配置

IOS真机调试必须reloading app... 后才能获取定位信息

初始化的代码放在 useEffect里,其他地方没有 AMapGeolocation 类的引入和使用。在xcode本地启动后会有如下报错, 但此时app还在lunach阶段, 并且后面定位一直不会获取。
image

如下操作 刷新app之后就能开始正常获取定位信息
image


useEffect(() => {
  amapLocationListener(user);
}, [])


// 高德地图持续定位
function amapLocationListener(user) {
  let apiKey = ""
  if (Platform.OS === "ios") {
    apiKey = Config.AMAP_KEY_IOS
  }
  if (Platform.OS === "android") {
    apiKey = Config.AMAP_KEY_ANDROID
  }
  if (apiKey) {
    try {
      // 设置 高德地图 apiKey
      AMapGeolocation.setApiKey(apiKey)
    } catch (error) {
      console.log("error:", error)
    }
  }
  console.log("apiKey: ", apiKey)

  // iOS 指定所需的精度级别
  AMapGeolocation.setDesiredAccuracy(3)
  // Android 指定所需的精度级别,可选设置,默认 高精度定位模式
  AMapGeolocation.setLocationMode(1)
  // 定位是否返回逆地理信息, 这里只要定位
  AMapGeolocation.setLocatingWithReGeocode(false)
  // 定位上报间隔
  AMapGeolocation.setInterval(3000)
  // 当设备可以正常联网时,还可以返回该定位点的对应的**境内位置信息(包括:省、市、区/县以及详细地址)。
  const listener = AMapGeolocation.addLocationListener((location) => {
    console.log("返回定位信息", location, user)
    locationReport(
      {
        coords: {
          longitude: location.longitude,
          latitude: location.latitude,
          speed: location.speed,
        },
        timestamp: location.timestamp,
      },
      user,
      "GCJ-02", // 用高德sdk获取的定位 使用的高德的坐标系
    )
  })

  // 开启监听
  AMapGeolocation.start()

  return () => {
    // 停止更新位置信息
    AMapGeolocation.stop()
    // 移除监听事件
    listener && listener.remove()
  }
}

iOS真机上报错

Invariant Violation: new NativeEventEmitter() requires a non-null argument., js engine: hermes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.