我已经卡在这里很长时间了,开始认为React Native Maps可能无法在Android模拟器上工作,因为我发现所有看起来能够工作的答案都是针对IOS的。
我目前正在使用Android模拟器运行我的应用程序。以下是一个简单地图的代码...
class MainMap extends Component {
constructor() {
super();
}
render(){
return (
<View style={styles.container}>
<MapView
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
justifyContent: 'flex-end',
alignItems: 'center',
},
map: {
position: 'absolute',
top: 0,
width:150,
height:150,
left: 0,
right: 0,
bottom: 0,
},
});
module.exports = MainMap;
代码看起来应该可以工作,因为我直接从一个例子中拿来的。我甚至从 Google API 获取了我的 API 密钥,然后在我的
AndroidManifest.xml
中添加了以下内容。<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="api here"/>
现在,当我运行
react-native run-android
时,应用程序似乎正常运行,没有错误消息。但是,应用程序是空白的。 View
容器加载正常,但其内容MapView
根本不加载。我看到的只是一个空白屏幕。请注意,我还在模拟器上安装了Google Play服务和Google API。
由于我根本没有收到任何错误消息,所以我该如何调试此问题?
react-native maps
在Android模拟器上能工作吗?编辑
我已经陷入困境很长时间了,这让我无法继续开发我的项目。由于问题的性质很难调试,所以我将提供一个github链接到我的存储库,以防有人愿意在他们的端上复制问题并查看我的问题是什么...
https://github.com/Bolboa/TTC-Mapping
我只需要地图加载。代码看起来应该可以工作,但地图没有加载...我将向任何能够帮助我的人提供赏金。
container
样式,其中包含以下内容:container: { flex: 1, justifyContent: 'flex-end', alignItems: 'center' }
。 - lwinkyawmyat