不能与谷歌地图API V2获得地图 [英] Can't get map with Google Map API V2
问题描述
我试图通过使用谷歌地图API V2让我的应用程序简单的地图;我跟所有的步骤去做,但是当我启动我的应用程序,我只能用谷歌标志的左下角白拿的页面。
I'm trying to get a simple map on my app by using Google Map API V2; I followed all the steps to do it but when I launch my app, I only get white page with a Google logo in the left bottom.
如果有人能帮助我,这将是巨大的。
If someone can help me with this, it will be great..
这是XML文件:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
这是文件的Java:
package com.example.ismail.location_test;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
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 {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
最后的清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="21" />
<uses-permission android:name="com.example.ismail.location_test.permission.MAPS_RECEIVE"/>
<permission android:name="com.example.ismail.location_test.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<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:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBbHBnsC_YhHKQhhsnaahYiT3GltK52It0" />
<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>
推荐答案
我怀疑三件事错在你的code:
I suspect 3 things wrong in your code :
(1)在使用它之前声明权限:
(1) Declare permission before using it :
<permission android:name="com.example.ismail.location_test.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<!-- after declare use this -->
<uses-permission android:name="com.example.ismail.location_test.permission.MAPS_RECEIVE"/>
(2)缺少声明版本的克数变量:
(2) Missing Declare gms version variable :
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
(3)缺少申报API_KEY:
(3) Missing declare API_KEY :
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaS33yBBDxSDFsdf33BK-7HCasdfSADFfa72wJnKLZvq6A" />
请与上述3名犯罪嫌疑人先检查:那么,如果仍错误那里,您可以重新确认步骤,使从的这里
Please check with above 3 suspects first : then if still error is there you can re-confirm steps to enable Google Maps from here
这篇关于不能与谷歌地图API V2获得地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!