【问题标题】:Error : Native Module RNGeocoder tried to override RNGeocoderModule when I use the react-native-geocoder package in react native错误:当我在 react native 中使用 react-native-geocoder 包时,本机模块 RNGeocoder 试图覆盖 RNGeocoderModule
【发布时间】:2019-08-01 00:28:46
【问题描述】:

我正在构建一个 React Native 应用程序,在这个应用程序中,我需要获取特定区域的位置,即街道地址、城市和国家/地区。

我正在尝试使用 react-native-geocoder 包来获取此信息。

当我按照教程编辑我的 MainApplication.java、setting.gradle、build.gradle 和我的代码时;

包的tutotiral和github repo的链接 https://github.com/devfd/react-native-geocoder

_getLocationAsync = async () => {

    var NY = {
          lat: 40.7809261,
          lng: -73.9637594
        };
    Geocoder.geocodePosition(NY).then(res => {
     this.setState({
       locationObj: res
     });
     console.log(res)
    // res is an Array of geocoding object (see below)
    })
   .catch(err => console.log(err))

    this.setState({
        procesingLocation: false,
    });   
};

我的模拟器屏幕上出现以下错误;

本机模块 RNGeocoder 试图覆盖 RNGeocoderModule。检查 MainApplication.java 中的 getPackages() 方法,可能是该模块被创建了两次。如果这是你的意图设置 canoverrideExistingModule=true

我的 MainApplication.java 看起来有以下代码;

import com.devfd.RNGeocoder.RNGeocoderPackage;

@Override
protected List<ReactPackage> getPackages() {
  @SuppressWarnings("UnnecessaryLocalVariable")
  List<ReactPackage> packages = new PackageList(this).getPackages();
  // Packages that cannot be autolinked yet can be added manually here, for example:
  // packages.add(new MyReactNativePackage());
  packages.add(new RNGeocoderPackage());
  return packages;
}

如有任何帮助,我们将不胜感激。

【问题讨论】:

标签: android react-native react-native-android


【解决方案1】:

试试删除下面的代码怎么样?

packages.add(new RNGeocoderPackage());

较新版本的 React Native 似乎做了自动链接,这意味着我们不必再次手动添加包。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多