Coo*_*att 13 android google-maps-android-api-2
我曾尝试使用之前Google_Play_SERVICE/SAMPLE使用所有可用选项提供的Google地图示例代码,并显示以下日志.
01-14 17:58:39.773:E/Google Maps Android API(13114):授权失败.
它显示了所有示例Map选项的空白屏幕.
现在我创建了一个新项目,这里是完整的代码: -
Activity.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-------");
}
}
Run Code Online (Sandbox Code Playgroud)
activity_map.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"/>
Run Code Online (Sandbox Code Playgroud)
的Manifest.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>
Run Code Online (Sandbox Code Playgroud)
LOG
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.
Run Code Online (Sandbox Code Playgroud)
截图

这是结果,带有缩放选项的空白屏幕,MapView中没有地图.
我遵循了以下每一步: -
1.)教程
BBo*_*Doo 26
请检查..
检查项目中是否存在包含"android-support-v4.jar"的"libs"文件夹.
"android-support-v4.jar"位于"android-sdk"drectory下的"/extras/android/compatibility/v4/android-support-v4.jar"中.
在运行项目之前,必须将项目构建目标设置为"Google API",而不是Android xx版本:选择项目并单击Eclipse中的项目>属性>项目构建目标并选择任何"Google API",然后运行项目在你的手机上.如果您使用模拟器,还必须将模拟器的AVD设置为任何"Google API".
再一次,您无需创建新的Google Maps API密钥即可测试您的项目,只需使用默认提供的API密钥,该密钥在Google API控制台中显示为"浏览器应用的密钥(带有引用者)" .
最后,最重要的是将Google Play服务添加为Android库项目,如下所示:
选择File> Import> Android> Existing Android Code Into Workspace,然后单击Next.选择Browse ...,输入/ extras/google/google_play_services/libproject/google-play-services_lib,然后单击Finish.
gaf*_*ach 15
我编译了你的代码,我得到了地图.我想我发现了问题:错误的凭据被缓存了.
我第一次运行你的代码,它使用了错误的凭据.虽然我已修复它们,但我仍然遇到"授权失败"错误.然后我只是卸载了应用程序,再次运行它,然后地图开始工作.
显然谷歌地图凭据在某处缓存.简化再次运行应用程序不会覆盖它们.
这也解释了为什么我在使用Debug As(不是Run As)运行我的其他应用程序后才能使用地图...
我遇到了和你一样的问题,我只有在通过"Debug As> Android Application"在真实设备上运行应用程序时才能使用地图.
我是Android开发的新手.我不知道这是不是事情的方式,或者我们错过了什么:)
| 归档时间: |
|
| 查看次数: |
35400 次 |
| 最近记录: |