使用react-native-maps时,地图在Android模拟器上不显示

时间:2016-04-20 09:19:47

标签: android google-maps react-native

我正在使用react-native-maps进行android开发。我按照此链接的说明进行操作:https://github.com/lelandrichardson/react-native-maps/blob/master/docs/installation.md。启动应用程序后,UI不会显示地图。相反,它显示一个空页面。以下是我使用的代码。类似的代码在iOS模拟器上运行良好。我不知道为什么不在android上工作。

import React, {


AppRegistry,
  Component,
  StyleSheet,
  Text,
  View,
  Image,
  ListView,
  TextInput,
  TouchableHighlight,
  Dimensions,
  MaterialButtonFixed,
 //MapView,
} from 'react-native';

import MapView from 'react-native-maps';


class MapPage extends Component{

    constructor(props){
        super(props);
        this.state = {
            region:{
                latitude: 4.21048,
                longitude: 101.97577,
                latitudeDelta: 1,
                longitudeDelta: 10,
            }
        }
    }

    onRegionChange(region){
        console.log('region changed ', region);
        this.setState({region});

    }

    render() {
        return(
            <View style={styles.container}>
                <MapView 
                      ref="map"
                   style={ styles.map }
                   mapType={"standard"}
                   region={this.state.region}
                   zoomEnabled={true}
                   scrollEnabled={true}
                   showsScale={true}
                   onRegionChange={this.onRegionChange.bind(this)}
                 >

                 </MapView>
            </View>
            )
    }
}

const styles = StyleSheet.create({
  map: {
    position: 'absolute',
    top: 0,
    left: 0,
    right: 0,
    bottom: 0,
  },
  container: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    padding: 30,
    marginTop: 65,
    flex:1,
    padding: 30,
    alignItems: 'center',
    // flexDirection: 'row',
    alignSelf: 'stretch',
    backgroundColor: 'red',
  },
  inputText: {

    height: 36,
      padding: 4,
      marginRight: 5,
      flex: 4,
      fontSize: 18,
      borderWidth: 1,
      borderColor: '#48BBEC',
      borderRadius: 8,
      color: '#48BBEC'
  }
});


module.exports = MapPage;

2 个答案:

答案 0 :(得分:2)

这是已知问题,尤其是在Android 4.x上。可能有几个问题导致这种情况,但首先要做的是将Google Apps(和Play服务)添加到您的模拟器中:How to install Google Play Services in a Genymotion VM (with no drag and drop support)?

另请参阅react-native-maps repo的问题部分,可能会有一些有用的线索来解决您的问题。

答案 1 :(得分:0)

我有类似的问题。我使用adb logcat来跟踪它。

我发现我的包链接(用react-native link修复了它)和模拟器设备有问题。

我在这里添加了对我的解决方案的详细说明: Android Warning: Native component for "AIRMap" does not exist