在 android 上使用地理定位或 MapView 反应 Native expo 项目错误
React Native expo project error with geolocation or MapView on android
所以:
我已经通过 Expo 完成了 React Native 项目。它有几个视图,airbnb mapView 和类似的东西。它以前是纯粹的 React Native 项目(甚至在 create-react-native-app 出现之前就制作了),我最近将它移到了 expo。几乎一切正常。 iOS 到 expo 的转换非常好,并且在那方面一切都按预期进行。但是我在 android phone.
上尝试启动应用程序时遇到了非常奇怪的错误
尝试在空对象引用上调用接口方法'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
他最终得出了与我相同的结论,但对他的问题知之甚少,也没有 answers/comments 所以我决定提出自己的问题。
在 Android 上将空选项对象作为第三个参数传递给 watchPosition
。
所以:
我已经通过 Expo 完成了 React Native 项目。它有几个视图,airbnb mapView 和类似的东西。它以前是纯粹的 React Native 项目(甚至在 create-react-native-app 出现之前就制作了),我最近将它移到了 expo。几乎一切正常。 iOS 到 expo 的转换非常好,并且在那方面一切都按预期进行。但是我在 android phone.
上尝试启动应用程序时遇到了非常奇怪的错误尝试在空对象引用上调用接口方法'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 他最终得出了与我相同的结论,但对他的问题知之甚少,也没有 answers/comments 所以我决定提出自己的问题。
在 Android 上将空选项对象作为第三个参数传递给 watchPosition
。