【问题标题】:React Native expo project error with geolocation or MapView on androidReact Native expo 项目错误与 android 上的地理位置或 MapView
【发布时间】:2017-09-12 17:48:14
【问题描述】:

所以:

我已经通过 Expo 制作了 React Native 项目。它有几个视图,airbnb mapView 和类似的东西。它以前是纯粹的 react native 项目(在 create-react-native-app 甚至是一件事之前制作),我最近将它移到了 expo。几乎一切正常。转换为 expo 对 iOS 来说非常好,并且在这方面一切都按预期工作。但是当我尝试在安卓手机上启动应用程序时,我遇到了非常奇怪的错误。

尝试在空对象引用上调用接口方法“boolean abi20_0_0.com.facebook.react.bridge.ReadableMap.hasKey(java.lang.String)”

我认为这与查找位置的实际过程有关,而不是真正的 mapView,但我唯一改变的是:

import MapView from 'react-native-maps';import { MapView } from 'expo';

这是用于查找位置的实际代码:

componentDidMount() {
    navigator.geolocation.getCurrentPosition(
            (position) => {
            this.setState({
                    region: {
                        latitude: position.coords.latitude,
                        longitude: position.coords.longitude,
                        latitudeDelta: LATITUDE_DELTA,
                        longitudeDelta: LONGITUDE_DELTA
                    },
                    lat : position.coords.latitude,
                    lon : position.coords.longitude,
                    cords : {
                          latitude: position.coords.latitude,
                        longitude: position.coords.longitude,
                }
                });
            },
            (error) => alert(error.message),
        {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
    );

    this.watchID = navigator.geolocation.watchPosition(
        (position) => {
            this.setState({
                    cords : {
                        latitude: position.coords.latitude,
                        longitude: position.coords.longitude,
                    },
                    lat : position.coords.latitude,
                    lon : position.coords.longitude,
                });
        });
 }

在没有expo的旧android版本上仍然可以正常工作,在用expo制作的新iOS版本上也可以正常工作。

package.json 依赖

"dependencies": {
    "expo": "^20.0.0",
    "firebase": "^4.3.0",
    "react": "16.0.0-alpha.12",
    "react-native": "https://github.com/expo/react-native/archive/sdk-20.0.0.tar.gz",
    "react-navigation": "^1.0.0-beta.11"
  }

我针对这个完全相同的问题提出了另一个问题: watchPosition fails with react native expo 他最终得出了与我相同的结论,但对他的问题知之甚少,也没有答案/cmets,所以我决定提出自己的问题。

【问题讨论】:

  • 你试过真机吗?不是模拟器?
  • 我尝试了 2 个真实设备和模拟器。仅在 iOS 真实设备上。每个设备/模拟器上的独立版本和博览会版本。没有博览会的旧版本适用于其中的每一个

标签: javascript android react-native expo


【解决方案1】:

在 Android 上将空选项对象作为第三个参数传递给 watchPosition

https://github.com/facebook/react-native/issues/14580

【讨论】:

  • 我很久以前就解决了这个问题。可以确认这有帮助。出现错误是因为 watchPosition api 在不同的 RN 版本之间发生了变化。接受你的答案是正确的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-17
  • 2023-02-25
  • 1970-01-01
  • 2016-01-25
  • 1970-01-01
  • 1970-01-01
  • 2021-07-14
相关资源
最近更新 更多