【问题标题】:Google Map Showing blank page in my android app?谷歌地图在我的安卓应用中显示空白页?
【发布时间】:2017-04-22 13:03:53
【问题描述】:

我正在尝试在比萨应用程序中实现谷歌我的应用程序,但它显示空白页面我该怎么办?

在我的 java 代码下面。

public class FindUsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_find_us);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;


    LatLng sydney = new LatLng(56.855776, 14.829839);

    Marker DSlocation = mMap.addMarker(new MarkerOptions().position(sydney).title("Maestro restaurang &
pizzeria").snippet("Click Navigation icon below for navigation"));

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,18));
} }

我的xml文件

 <fragment
     xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:map="http://schemas.android.com/apk/res-auto"
         xmlns:tools="http://schemas.android.com/tools"
         android:id="@+id/map"
         android:name="com.google.android.gms.maps.SupportMapFragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         tools:context="com.example.yodgor777.maestro.FindUsActivity" />

我的清单

 <?xml version="1.0" encoding="utf-8"?> <manifest
 xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.yodgor777.maestro">

不需要 ACCESS_COARSE/FINE_LOCATION 权限即可使用 Google Maps Android API v2,但您必须指定粗略或精细 “我的位置”功能的位置权限。 -->

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".HomeScreenActivity"
            android:label="@string/title_activity_home_screen" />
        <activity android:name=".MainActivity" />
        <activity android:name=".Information" />
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".FindUsActivity"
            android:label="@string/title_activity_find_us"></activity>
    </application>

 </manifest>

【问题讨论】:

    标签: java android google-maps


    【解决方案1】:

    在 manifest.xml 中添加此权限

      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    

    更改您的谷歌地图 Apikey,然后尝试并检查您是否 google map api 密钥是否为 enable

    【讨论】:

    • 我已经实现了新的 api 密钥并添加了您的代码以显示它仍然显示空白。 --> AIzaSyBnJFSGMRpgyBogcfwAHM8JSfuJ4c1FNaM
    【解决方案2】:

    启用地图 API

    接下来,添加包名和指纹。这提供了两个字段,一个用于添加包名称,另一个用于从您的应用程序签名密钥添加 SHA1。

    您可以使用以下命令生成 SHA1:

    keytool -list -v -keystore debug.keystore
    

    创建 SHA1 密钥并将其输入文本字段后,单击蓝色的创建按钮。然后,您会看到一个对话框,其中包含您需要添加到 Android 应用以访问 Maps API 的 API 密钥。

    参考: google developer console:

    【讨论】:

      猜你喜欢
      • 2018-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多