我在Android应用程序中使用谷歌地图。我创建了密钥并在清单文件中添加了必要的权限:
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com..."
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="com....MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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.NoActionBar">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key"/>
<activity
android:name=".activities.MainActivity"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
谷歌地图-api.xml:
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
AIzaSyAjGQ-...
</string>
另外,我已经将以下依赖compile 'com.google.android.gms:play-services:8.4.0'
添加到编译中,它正在运行:
app.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com..."
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
}
我还将google-services.json
添加到 PROJECT_NAME / app / :
但是当应用程序启动时,我在调试器中收到此消息:
GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
我已经按照link的步骤进行了操作,但就我的情况而言,我可以错过哪些配置?
答案 0 :(得分:3)
我认为
build.gradle
的底部:申请插件:'com.google.gms.google-services'
build.gradle
:classpath'com.google.gms:google-services:1.5.0-beta2'
了解更多信息Check this
新build.gradle
看起来像
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com..."
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
}
答案 1 :(得分:0)
答案 2 :(得分:0)
之后<string name="google_maps_key">Your Api Key</string>
您的项目。
并确保您的API_KEY字符串资源可用,名为
<script> $(document).ready(function() { $('.howisthiscalculated').magnificPopup({ type: 'inline' }); }); </script>
。