简体   繁体   English

React-Native-Maps:地图为空。 仅显示 Google 徽标和标记

[英]React-Native-Maps: Map is empty. Only shows Google logo and Marker

I am using react-native-maps and the version is "react-native-maps": "0.27.1" .我正在使用react-native-maps ,版本是"react-native-maps": "0.27.1"

I was able to view the map on Friday, 1st October 2021 .我能够在2021 年 10 月 1 日星期五查看地图。

However, today ( Monday, 4th October 2021 ) I am getting blank map with Google logo and just the Marker for location.但是,今天( 2021 年 10 月 4 日,星期一)我得到了带有 Google 徽标的空白地图和位置标记。

I tried troubleshooting from the react-native-maps (ie google_maps_api.xml , PROVIDER_GOOGLE ) but it didn't solve the issue.我尝试从 react-native-maps (即google_maps_api.xmlPROVIDER_GOOGLE )进行故障排除,但它没有解决问题。

It also mentioned it could be API KEY issue but I have been using the same API key for this project when it first worked ( I also have billing enabled ).它还提到它可能是 API KEY 问题,但我在这个项目第一次工作时一直使用相同的 API 密钥(我也启用了计费)。

I did not make any changes to my file nor did I add anything new but the map still fails to load我没有对文件进行任何更改,也没有添加任何新内容,但地图仍然无法加载

I have another project with the same version "react-native-maps": "0.27.1" and it seems to be running fine and displays the map.我有另一个具有相同版本"react-native-maps": "0.27.1" ,它似乎运行良好并显示地图。

Here's my code snippet and other files:这是我的代码片段和其他文件:

MapScreen.js: MapScreen.js:

import React, {Component} from 'react';
import {View, StyleSheet} from 'react-native';
import MapView, {Marker} from 'react-native-maps';

class DeliveryRoute extends Component {
  constructor(props) {
    super(props);
    this.state = {
      region: {
        latitude: parseFloat(5.3302),
        longitude: parseFloat(103.1408),
        latitudeDelta: 0.002,
        longitudeDelta: 0.002,
      },
    };
  }

  renderMap() {
    return (
      <View style={styles.flex}>
        <MapView
          style={styles.map}
          initialRegion={this.state.region}>
          <Marker coordinate={this.state.region} pinColor="red" />
        </MapView>
      </View>
    );
  }

  render() {
    return <>{this.renderMap()}</>;
  }
}

const styles = StyleSheet.create({
  flex: {
    flex: 1,
  },
  map: {
    ...StyleSheet.absoluteFillObject,
  },
});

export default DeliveryRoute;

android\build.gradle: android\build.gradle:

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 21
        compileSdkVersion = 29
        targetSdkVersion = 29
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.0.0")

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

android\app\build.gradle: android\app\build.gradle:

构建 gradle 应用程序

android\app\src\main\AndroidManifest.xml: android\app\src\main\AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.skydrivesolution.foodtigerdriver">
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  <uses-permission android:name="android.permission.VIBRATE"/>
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  <uses-permission android:name="android.permission.WAKE_LOCK"/>
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
  <application android:usesCleartextTraffic="true" android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme">
    <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/@dimovdaniel/foodtiger"/>
    <meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="40.0.0"/>
    <meta-data android:name="expo.modules.updates.ENABLED" android:value="true"/>
    <meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
    <meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="xxx"/>
    <uses-library android:name="org.apache.http.legacy" android:required="false"/>
    <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="com.skydrivesolution.foodtigerdriver"/>
      </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
  </application>
</manifest>

Screenshot:截屏:

谷歌地图截图

SOLVED解决了

It was indeed an API issue on Google Cloud Platform这确实是 Google Cloud Platform 上的 API 问题

在 iOS 中将 provider 属性设置为DEFAULT_PROVIDER为我修复

provider={ Platform.OS === 'ios' ? PROVIDER_DEFAULT : PROVIDER_GOOGLE }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM