【问题标题】:google maps android api v2 using supportmapfragment谷歌使用supportmapfragment映射android api v2
【发布时间】:2013-07-25 05:27:01
【问题描述】:

我尝试安装存在于tutorial 中的项目:

一切正常,但是运行项目时,logcat 说:

“找不到类'maps.ag.l',引用自方法maps.ah.an.a”

地图是空的,logcat说:

" 无法加载地图。联系 Google 服务器时出错。这可能是身份验证问题(但可能是由于网络错误)。

我已将包名称从“in.wptrafficanalyzer.locationgooglemapv2demo”更改为“it.appatwork”,并且我的 sha1 已获得 android maps apiV2 的 apikey。

我有安卓 2.3.3

请帮帮我!

主要活动:

package it.appatwork.locationgooglemapv2demo;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;

public class MainActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable (getApplicationContext());
    if(status == ConnectionResult.SUCCESS) {
        System.out.println("ok");
    }

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

activity_main.xml:

<RelativeLayout 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"
tools:context=".MainActivity" >

<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"/>
</RelativeLayout>

AndoridManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.appatwork.locationgooglemapv2demo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<permission
      android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"
      android:protectionLevel="signature"/>

<uses-permission android:name="it.appatwork.locationgooglemapv2demo.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"/>


<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="it.appatwork.locationgooglemapv2demo.MainActivity"
        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="AIzaSyBgkEwv0Z4O2t27avrve_33N33QY0wHNXg"/>        

</application>

</manifest>

更新:

这是 logcat 输出:

07-24 23:11:40.849: W/dalvikvm(6472): VFY: unable to resolve instance field 24 07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/p/w; (718) 07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/p/w;' failed 07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/aq/as; (5347) 07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/aq/as;' failed 07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/ag/l; (4576) 07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/ag/l;' failed 07-24 23:11:41.149: E/dalvikvm(6472): Could not find class 'maps.ag.l', referenced from method maps.ah.an.a 07-24 23:11:41.149: W/dalvikvm(6472): VFY: unable to resolve new-instance 4420 (Lmaps/ag/l;) in Lmaps/ah/an; 07-24 23:11:41.359: I/ApplicationPackageManager(6472): cscCountry is not German : WIN 07-24 23:11:47.069: W/Google Maps Android API(6472): Please add &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt; into AndroidManifest.xml to ensure correct behavior under poor connectivity conditions. 07-24 23:11:47.069: I/Google Maps Android API(6472): Failed to contact Google servers. Another attempt will be made when connectivity is established. 07-24 23:11:59.009: W/IInputConnectionWrapper(6472): getExtractedText on inactive InputConnection 07-24 23:11:59.009: W/IInputConnectionWrapper(6472): getExtractedText on inactive InputConnection 07-24 23:12:02.289: E/Google Maps Android API(6472): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

【问题讨论】:

    标签: android google-maps google-maps-android-api-2


    【解决方案1】:

    首先,您描述的两个问题彼此无关,您的主要问题在这里:

    加载地图失败。联系 Google 服务器时出错。这大概是 身份验证问题(但可能是由于网络错误)。

    这意味着您在清单文件中的权限或您在 Google API 控制台中的配置存在某种问题。

    请仔细阅读这两篇博文 Google Maps API V2 keyGoogle Maps API V2 的所有步骤,并提交所有步骤,如果您仍然有问题,请在此处发布您的代码和更新的 logcat 消息。

    更新:

    你的包名:

    package="it.appatwork.locationgooglemapv2demo"
    

    与您在权限中指定的包名不匹配:

    permission
          android:name="it.appatwork.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"
          android:protectionLevel="signature"/>
    
    <uses-permission android:name="it.appatwork.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"/>
    

    我认为它区分大小写,所以尝试将其更改为:

    permission
          android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"
          android:protectionLevel="signature"/>
    
    <uses-permission android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"/>
    

    【讨论】:

    • 感谢 emil,但我已经阅读了它...我已经阅读了很多关于这个主题的教程和帖子,遵循提示,但没有,不工作...总是相同的消息
    • 我已经改变了AndroidManifest(我已经发布了新版本),但是logcat的输出没有改变......
    • @DavideDiFilippo:我有同样的问题,我正在尝试解决它。​​我解决了我在这里发布解决方案。让告诉我你解决了..
    • 它工作! :) 我到处都更改了 it.appatwork.locationgooglemapv2demo -> it.appatwork.lgv2,并且我已经将应用程序的名称从 mainactivity -> lgv2 ....并且我添加了布局文件 xmlns:map="@987654323 @" 在地图片段中.....
    • 那么在进行建议的编辑后,地图开始工作了吗?
    猜你喜欢
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多