【问题标题】:Google Map is not showing in react native only Google Logo is visible谷歌地图未在本机反应中显示,只有谷歌徽标可见
【发布时间】:2022-01-17 12:35:27
【问题描述】:

我分配了正确的 Api 密钥,为什么地图没有显示?我 App.js 代码

import MapView from 'react-native-maps';

export default function App() {
  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: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

我的安卓模拟器显示了这个结果

【问题讨论】:

  • 您是否添加了 Google Map API 密钥?
  • 是的,我也添加了 Google Map Api,但地图没有显示只有 google 徽标可见

标签: react-native google-maps google-maps-api-3 react-native-maps


【解决方案1】:

将样式添加到 MapView 并给出 absoluteFillObject。

MapView: {
    ...StyleSheet.absoluteFillObject,
    top: 10, //depends on your screen
    backgroundColor: 'transparent',
  }

【讨论】:

  • 我也添加了这个但结果相同
  • 在新屏幕中尝试并导出到 app.js
【解决方案2】:

我在示例项目中尝试了以下内容。请尝试这样 -

const App = () => {return (
  <MapView
      style={{flex: 1}}
      provider={PROVIDER_GOOGLE}
      minZoomLevel={6}
      onMapReady={() => {}}
  >
  
  </MapView>);};

如果这对你有用,请告诉我。

【讨论】:

  • 我需要在谷歌提供者中添加什么?
  • 你能分享完整的代码和所有步骤吗?请我花一整天的时间
  • 删除该提供程序。上面的例子仍然有效。
【解决方案3】:

@ReactDev 你能试试这个代码吗?

import React from 'react';
import { StyleSheet, View, Dimensions } from 'react-native';

import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';

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

const ASPECT_RATIO = width / height;
const LATITUDE = 37.78825;
const LONGITUDE = -122.4324;
const LATITUDE_DELTA = 0.0922;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;


render() {
  return (
    <View style={styles.container}>
        <MapView
          provider={PROVIDER_GOOGLE}
          style={styles.map}
          initialRegion={{
            latitude: LATITUDE,
            longitude: LONGITUDE,
            latitudeDelta: LATITUDE_DELTA,
            longitudeDelta: LONGITUDE_DELTA,
          }}
        />
      </View>
  );
}

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

【讨论】:

  • 我正在添加这样的 google Api 密钥,这是笨拙的密钥,语法很好,我在 android manifesto 文件中应用了这个
  • @ReactDev 是的,所以如果我覆盖我的代码,它不起作用吗?
猜你喜欢
  • 1970-01-01
  • 2018-11-02
  • 1970-01-01
  • 2018-07-22
  • 2010-10-28
  • 2018-11-15
  • 1970-01-01
  • 1970-01-01
  • 2013-04-20
相关资源
最近更新 更多