簡體   English   中英

使用react-native-maps時,android模擬器上未顯示地圖

[英]Map doesn't shown on android simulator when using react-native-maps

我正在使用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;

這是已知問題,尤其是在Android 4.x上。 可能有幾個問題導致此問題,但首先要做的是將Google Apps(和Play服務)添加到模擬器中: 如何在Genymotion VM中安裝Google Play服務(不支持拖放)?

另請閱讀react-native-maps存儲庫中的“問題”部分,可能會有有用的線索來解決您的問題。

我有一個類似的問題。 我使用adb logcat進行跟蹤。

我發現程序包鏈接(已使用react-native link修復)和模擬器設備存在問題。

我在這里添加了我的解決方案的詳細說明: Android警告:“ AIRMap”的本地組件不存在

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM