【发布时间】: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;
}
如有任何帮助,我们将不胜感激。
【问题讨论】:
-
我无法以我的知识解决这个问题。对不起。
-
我遇到了类似的问题,使用了不同的包:github.com/mauron85/react-native-background-geolocation/issues/…
标签: android react-native react-native-android