2016-11-29 102 views
3

我一直在這個很長一段時間現在,我開始思考也許反應原生地圖不能在Android模擬器上工作,因爲所有的答案,我覺得似乎無論如何,工作都是爲了IOS。反應原生地圖不加載爲Android(空白地圖)

我目前使用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; 

該代碼似乎應該工作,因爲我直接從一個例子。我甚至得到了來自谷歌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

我只需要加載地圖。該代碼看起來像它應該工作,但地圖不會加載...

我會給任何人誰可以幫助我一個賞金。

+0

嘗試'container' style with'container:{flex:1,justifyContent:'flex-end', alignItems:'center',}。 –

+0

@ubatin我試過這個。看起來地圖根本就沒有加載... – Bolboa

+0

你是否嘗試在google api控制檯上刪除api密鑰的簽名?我的意思是包名和SHA1密鑰。它是調試密鑰和釋放密鑰的問題。我只是問你是否考慮過這種方法? –

回答

4

給款式MapView

包括

var { width, height } = Dimensions.get('window') 

渲染方法

<View style={styles.container}> 
     <MapView style = {styles.mapcontainer} 
      showsUserLocation={true} 
      showsMyLocationButton={false} 
      zoomEnabled = {true} 
      region={this.state.region} > 
     </MapView> 
</View> 

包括風格

container: { 
    flex: 1, 
    }, 
mapcontainer: { 
    flex: 1, 
    width: width, 
    height: height, 
    }, 
+0

@Bolboa:你有試過這個解決方案嗎? –

+0

對不起,我一直忙於其他工作,但今天我會試一試:) – Bolboa

1

你只創建與map風格styles變量,但你沒有應用該樣式的MapView 。 您需要添加下面一行將指定樣式的MapView

style={styles.map} 

以至於現在它看起來像

<View style={styles.container}> 
    <MapView 
     style={styles.map} 
     initialRegion={{ 
      latitude: 37.78825, 
      longitude: -122.4324, 
      latitudeDelta: 0.0922, 
      longitudeDelta: 0.0421, 
     }}/> 
</View> 

也看看troubleshooting節你錯過了包括第二部分。
如果即使在添加樣式後無法看到地圖,您的密鑰也會出現問題。