2016-07-25 171 views
2

我一直在使用的阵营,本机地图图书馆从https://github.com/lelandrichardson/react-native-maps/blob/master/docs/installation.md如何实现谷歌地图在阵营Android本地(阵营 - 本机地图)

我已经照着所有的步骤滴注,但我已经仍然收到一个空白屏幕(整个反应屏幕是白色的,就像没有渲染)。

但是,当我尝试呈现一个元素的反应,文本弹出。因此,我的地图没有显示出来,这是我执行库的结果,而不是反应的问题。

这里是我的index.android.js页面代码

/** 
* Sample React Native App 
* https://github.com/facebook/react-native 
* @flow 
*/ 

import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    StyleSheet, 
    Text, 
    View 
} from 'react-native'; 
import MapView from 'react-native-maps'; 

class roads extends Component { 
    render() { 
    return (
     <View style={styles.container}> 
<MapView 
style={styles.map} 
    initialRegion={{ 
     latitude: 37.78825, 
     longitude: -122.4324, 
     latitudeDelta: 0.0922, 
     longitudeDelta: 0.0421, 
    }} 
    /> 
     </View> 
    ); 
    } 
} 

const styles = StyleSheet.create({ 
    container: { 
    flex: 1, 
    justifyContent: 'center', 
    alignItems: 'center', 
    backgroundColor: '#F5FCFF', 
    }, 
map: { 
    position: 'absolute', 
    top: 0, 
    left: 0, 
    }, 
}); 

AppRegistry.registerComponent('roads',() => roads); 

我也接受我的手机上此错误消息

warning encountered 4 times. 
Show Stacktrace 
Unable to symbolicate stack trace: The stack is null 

这是最接近线程我发现关于错误,但它应该是固定的... https://github.com/facebook/react-native/issues/8311

我也检查了我的API权限对谷歌开发者利弊ole,我仍然无法让我的地图显示出来(它表示它正在接收API请求)。那么有谁知道如何将谷歌地图实施到我的应用程序?

+0

是,在仿真器或真实设备? –

+0

在真实设备上。有什么不同? –

+0

在运行地图的模拟器上,您还必须安装Google Play服务。您是否在运行应用程序时尝试登录?在终端的一个选项卡中运行以下代码'adb logcat'*:S'ReactNative:V ReactNativeJS:V -d> Desktop/log.txt'并从另一个选项卡运行您的应用程序。 –

回答

6

Map组件没有得到任何可用于确定其大小的属性。因此,它是0x0像素大,不被看到。为了解决这个问题,你需要添加这些属性之一styles.map

  • 柔性
  • 高度&宽度
  • 权&底部
+1

是的,设置例如。 'MapView'上的'flex:1'应该可以工作。 – Carl

+1

谢谢!对于其他人,您必须删除标签,并将宽度和高度设置为空以使地图变为全屏。 –