簡體   English   中英

在Android上反應本機地圖

[英]React Native Maps on Android

我按照air-bnb安裝指南的指示按照步驟創建了容器。 我在容器底部看到一個google徽標,這意味着我的初始化步驟正確,但是地圖內容未加載。 我在清單中包含api密鑰:

<meta-data
     android:name="com.google.android.geo.API_KEY"
     android:value="mydummmmmmmmmmyApiKeyyyyyyyyyyyyyyyyyyy"/>

正確嗎? 該文檔似乎說將其放在兩個括號之間,如下所示:

<meta-data
         android:name="com.google.android.geo.API_KEY"
         android:value="{{mydummmmmmmmmmyApiKeyyyyyyyyyyyyyyyyyyy}}"/>

我都嘗試過,但沒有成功。

編輯:已解決

重新啟動后該地圖可見

使用api密鑰的正確方法是將其包含在清單中

<meta-data
             android:name="com.google.android.geo.API_KEY"
             android:value="mydummmmmmmmmmyApiKeyyyyyyyyyyyyyyyyyyy"/>
If you have a blank map issue, (#118, #176) try the following lines :

Set this Stylesheet in your map component

...
const styles = StyleSheet.create({
 container: {
   ...StyleSheet.absoluteFillObject,
   height: 400,
   width: 400,
   justifyContent: 'flex-end',
   alignItems: 'center',
 },
 map: {
   ...StyleSheet.absoluteFillObject,
 },
});

module.exports = class MyApp extends React.Component {
 render() {
   const { region } = this.props;
   console.log(region);

   return (
     <View style ={styles.container}>
       <MapView
         style={styles.map}
         region={{
           latitude: 37.78825,
           longitude: -122.4324,
           latitudeDelta: 0.015,
           longitudeDelta: 0.0121,
         }}
       >
       </MapView>
     </View>
   );
 }
}
Run "android" and make sure every packages is updated.
If not installed yet, you have to install the following packages :
Extras / Google Play services
Extras / Google Repository
Android 6.0 (API 23) / Google APIs Intel x86 Atom System Image Rev. 13
Check manual installation steps
Generate your SHA1 key :
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

Go to Google API Console and select your project, or create one.
In Overview -> Google Maps API -> Google Maps Android API -> Check if it's enabled
Create a new key by clicking on Create credentials -> API Key -> Android Key, enter the name of the API key and your SHA1 key, generated before, and create it. Check installation step 4.

Clean the cache :
watchman watch-del-all
npm cache clean

When starting emulator, make sure you have enabled Wipe user data.

Run react-native run-android

At this step it should work, but if not, go to your Google API Console and create a Browser key instead of a Android key and go to step 6.

暫無
暫無

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

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