我曾尝试使用之前Google_Play_SERVICE/SAMPLE
通过使用所有可用选项提供的谷歌地图示例代码,它显示了以下日志。
01-14 17:58:39.773:E/Google Maps Android API(13114):授权失败。
它向我展示了所有示例地图选项的空白屏幕。
现在我创建了一个新项目,这是它的完整代码:-
活动.java
public class MapActivity extends FragmentActivity
{
private Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
GoogleMap gMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
Log.e("Maps", "Result int value::" + result);
switch (result) {
case ConnectionResult.SUCCESS:
Log.e("Maps", "RESULT:: SUCCESS");
break;
case ConnectionResult.DEVELOPER_ERROR:
Log.e("Maps", "RESULT:: DE");
break;
case ConnectionResult.INTERNAL_ERROR:
Log.e("Maps", "RESULT:: IE");
break;
case ConnectionResult.INVALID_ACCOUNT:
Log.e("Maps", "RESULT:: IA");
break;
case ConnectionResult.NETWORK_ERROR:
Log.e("Maps", "RESULT:: NE");
break;
case ConnectionResult.RESOLUTION_REQUIRED:
Log.e("Maps", "RESULT:: RR");
break;
case ConnectionResult.SERVICE_DISABLED:
Log.e("Maps", "RESULT:: SD");
break;
case ConnectionResult.SERVICE_INVALID:
Log.e("Maps", "RESULT:: SI");
break;
case ConnectionResult.SERVICE_MISSING:
Log.e("Maps", "RESULT:: SM");
break;
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
Log.e("Maps", "RESULT:: SVUR");
break;
case ConnectionResult.SIGN_IN_REQUIRED:
Log.e("Maps", "RESULT:: SIR");
break;
default:
break;
}
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gMap.setMyLocationEnabled(true);
Log.e("Maps", "------EOC-------");
}
}
活动地图.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
清单.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.dottech.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:maxSdkVersion="17"
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="net.dottech.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="net.dottech.map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="net.dottech.map.MapActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="removed" />
</application>
</manifest>
日志
01-21 13:09:09.243: E/Maps(449): Result int value::0
01-21 13:09:09.243: E/Maps(449): RESULT:: SUCCESS
01-21 13:09:09.243: E/Maps(449): ------EOC-------
01-21 13:09:09.248: D/LocationManagerService(1852): gps location requested by an application
01-21 13:09:09.253: D/SensorManager(449): registerListener :: handle = 0 name= K3DH
Acceleration Sensor delay= 20000 Listener= maps.i.a@41a054f8
01-21 13:09:09.353: D/(449): Device driver API match
01-21 13:09:09.353: D/(449): Device driver API version: 10
01-21 13:09:09.353: D/(449): User space API version: 10
01-21 13:09:09.353: D/(449): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Fri May 4 10:32:42 KST 2012
01-21 13:09:12.398: D/Sensors(449): Remain listener = Sending .. normal delay 200ms
01-21 13:09:12.398: I/Sensors(449): sendDelay --- 200000000
01-21 13:09:12.398: I/Sensors(1852): setDelay :: handle = 0 delay = 200000000
01-21 13:09:12.398: D/SensorManager(449): JNI - sendDelay
01-21 16:14:17.835: E/Google Maps Android API(12168): Failed to load map. Could not contact Google servers.
截屏
这是结果,带有缩放选项的空白屏幕,MapView 中没有地图。
我遵循了以下提到的每一个步骤:-
1.)教程