2016-07-05 87 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