谷歌地图空白页与AndroidStudio
我是AndroidStudio的初学者,所以我尝试构建一个基本的应用程序。我添加了谷歌地图活动,效果很好。 然后我将Firebase添加到应用程序中,发现GoogleMapActivity不再工作了。它只是给我看一个在左下角有“谷歌”标志的空白页面。 我尝试在虚拟设备和真实设备上运行该程序。没有成功 我试图更改密钥,我也清理/重建了应用程序。 事实是。。。。logcat没有显示任何消息,甚至没有警告 我真的不明白为什么GoogleMapActivity以前能用,现在不能用了 你必须知道,当我添加Firebase时,我改变了很多依赖项。也许这是SDK版本控制的问题?我不知道 以下是我在AndroidManifest.xml中的权限:谷歌地图空白页与AndroidStudio,android,google-maps,android-studio,google-api,Android,Google Maps,Android Studio,Google Api,我是AndroidStudio的初学者,所以我尝试构建一个基本的应用程序。我添加了谷歌地图活动,效果很好。 然后我将Firebase添加到应用程序中,发现GoogleMapActivity不再工作了。它只是给我看一个在左下角有“谷歌”标志的空白页面。 我尝试在虚拟设备和真实设备上运行该程序。没有成功 我试图更改密钥,我也清理/重建了应用程序。 事实是。。。。logcat没有显示任何消息,甚至没有警告 我真的不明白为什么GoogleMapActivity以前能用,现在不能用了 你必须知道,当我添加
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<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" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.barcodelibrary.permission.MAPS_RECEIVE"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
编辑1:添加我的GoogleMapActivity代码
如您所见,这是AndroidStudio提供的基本活动。
我错过什么了吗
package com.kandel.myandroidapp;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
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));
}
}
编辑2:添加我的活动\u maps.xml文件
添加firebase时,必须将其google services.json
添加到project中。将firebase添加到project后,google地图将使用该文件中的密钥将其添加到清单文件中
` <meta-data
android:name="com.google.android.geo.API_KEY"
android:value="Your Api key" />`
``
要了解更多详细信息,请访问您应该在生成密钥时添加SHA-1指纹,您可以从android studio或命令行获得它。您可以通过以下链接生成它,并在生成地图的键时使用它 使用android studio生成它的步骤:
我已经加上了。Firebase运行良好,这不是重点。问题在于GoogleMap@HugoKandel好啊也许这是因为'implementation'com.google.android.gms:play services:12.0.1'`使用15.0.1而不是12.0.1版本,因为12.0.1是可能的“最高”版本。“播放服务”的15.0.1版本不存在。它与play services map不同,后者的版本为15.0.1。您可以解释为什么需要play services,因为当您添加它的孩子时,您不需要添加核心library@MRah我用我的GoogleMapActivity.java文件编辑了这篇文章。你需要将
添加到清单中。哦,对不起,我只是忘了在文章中添加它!但我已经在我的节目里看到这句话了。我编辑我的帖子,这样你就可以发布你的MapsActivity xmlDone了。正如您所看到的,这是AndroidStudio中的基本文件检查您是否在开发人员控制台中启用api密钥还检查SHA-1I我是初学者,所以。。。什么是SHA-1?
package com.kandel.myandroidapp;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
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));
}
}
<?xml version="1.0" encoding="utf-8"?>
<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=".MapsActivity" />
` <meta-data
android:name="com.google.android.geo.API_KEY"
android:value="Your Api key" />`