Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android按照readme里面的步骤集成后,调用getCurrentPosition报错 #124

Closed
chj-damon opened this issue Jun 18, 2020 · 10 comments
Closed
Labels
android Only for android bug Something isn't working

Comments

@chj-damon
Copy link

chj-damon commented Jun 18, 2020

为了节省大家的时间,请尽可能详细地说明问题,并最好提供截图(特别是出错信息)。

Geolocation.getCurrentPosition(({ coords }) => {
  console.log(coords);
});

报错信息:

TypeError: undefined is not a function(near '..._1.addLocationListener...')

RN 版本:0.62.2
react-native-amap-geolocation版本:1.1.0

@chj-damon chj-damon added android Only for android bug Something isn't working labels Jun 18, 2020
@chj-damon
Copy link
Author

根本原因在于APP启动的时候就报错:

TypeError: null is not an object (evaluating 'AMapGeolocation.init')
init@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:160650:27
_callee$@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:191011:88
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:26933:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27109:32
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:26933:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27009:30
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27019:21
tryCallOne@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:28871:16
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:28972:27
_callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:32411:17
_callImmediatesPass@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:32447:19
callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:32665:33
callImmediates@[native code]
__callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2730:35
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2516:34
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2713:15
flushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2515:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]

@fanriver
Copy link

fanriver commented Jun 19, 2020

同样的问题,
我看了下index.js里面的接口是这样的

`var react_native_1 = require("react-native");
var AMapGeolocation = react_native_1.NativeModules.AMapGeolocation;
var eventEmitter = new react_native_1.NativeEventEmitter(AMapGeolocation);

function init(key) {
return AMapGeolocation.init(react_native_1.Platform.select(key));
}`

但是android端的module里面接口是

@ReactMethod public void init(String key, Promise promise) { System.out.print("AMapGeolocation init" + key + "," + promise); if (client != null) { client.onDestroy(); } AMapLocationClient.setApiKey(key); client = new AMapLocationClient(reactContext); client.setLocationListener(this); eventEmitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class); promise.resolve(null); }
多了一个Promise参数,导致出现null问题,
但是不知道RN端的接口是不是没对应的进行修改导致了?也不知道该怎么改

@fanriver
Copy link

我尝试把react-native-amap-geolocation/lib/android/src/main/xxxxx/AMapGeolocationModule.java中的init接口修改了下,发现可以正常获取了,工程最好重新clean再编译一下。

`@ReactMethod
public void init(String key) {
System.out.print("AMapGeolocation init" + key );
if (client != null) {
client.onDestroy();
}

    AMapLocationClient.setApiKey(key);
    client = new AMapLocationClient(reactContext);
    client.setLocationListener(this);
    eventEmitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
    // promise.resolve(null);
}`

@chj-damon
Copy link
Author

我按照你的方法试了一下,还是报这个错。

@whereiscode
Copy link

@chj-damon 你那init可以过去吗?我这按着文档导出 说没有_reactNativeAmapGxxxxx.init方法

@chj-damon
Copy link
Author

过不去。还是在报错

@whereiscode
Copy link

@chj-damon 是啊 我iOS可以 安卓一直不能用 ,老版本的可以 这不升级后 用不了了

@whereiscode
Copy link

whereiscode commented Jun 23, 2020

@chj-damon 解决了 必须用await !!!
如果在redux里用yield 和 call IOS可以,安卓不可以
如果用await ios和安卓就都行,祝你好运

@qiuxiang
Copy link
Owner

qiuxiang commented Jun 23, 2020

确实有问题

@qiuxiang
Copy link
Owner

更新最新版就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Only for android bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants