2016-07-05 95 views
1

但我有我的Android應用 另一個問題我開發了一個非常基本的應用程序,其中包含一個單一的活動,並顯示谷歌地圖(我用谷歌地圖API)。編譯結束時沒有錯誤,我也生成了apk,沒有任何問題,但是當我在不同的設備上運行我的應用程序時,只會顯示一個空白頁面,並在此頁面下方顯示Google標誌。我需要幫助谷歌地圖API

[![This the screenshot of my application][1]][1] 


package com.example.amine.bea_mapapp; 

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

private GoogleMap mMap; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_maps); 
    // 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; 

    // Add a marker in Sydney and move the camera 
    LatLng sydney = new LatLng(-34, 151); 
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
    } 
    } 

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">My API key is here</string> 

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.amine.bea_mapapp"> 
<permission android:name="com.androidcom.example.amine.bea_mapapp.MAPS_RECEIVE" android:protectionLevel="signature"/> 
<uses-permission android:name="com.androidcom.example.amine.bea_mapapp.MAPS_RECEIVE"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="com.androidcom.example.amine.bea_mapapp.providers.gsf.permission.READ_GSFREVICES"/> 
<uses-feature android:glEsVersion="0x00020000" 
    android:required="true"/> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 

    <meta-data 
     android:name="com.google.android.geo.API_KEY" 
     android:value="My API key is here" /> 

    <activity 
     android:name=".MapsActivity" 
     android:label="@string/title_activity_maps"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

+1

在日誌中查找與您所生成的apk文件相關的api密鑰 –

+0

錯誤..?簽署apk或調試apk ..? –

回答

1

與谷歌API密鑰似乎問題。你在

<meta-data 
     android:name="com.google.android.geo.API_KEY" 
     android:value="My API key is here" /> 

使用什麼密鑰如果仍然有問題掙扎,生成一個與你的機器生成一個密鑰一個新的谷歌地圖API密鑰,並用新的地圖API密鑰構建APK。我相信它會適用於所有設備。

1

第一件事情,你需要檢查谷歌賬號在設備登錄或沒有 第二件事檢查內置地圖在您的測試設備工作正常與否。由於谷歌地圖訪問設備現有地圖應用程序和您的谷歌帳戶的一些服務。

+0

對於android應用程序中的地圖,這些東西是強制性的。 – Ramkailash