无法加载地图。错误接触谷歌服务器。这可能是一个身份验证问题 [英] Failed to load map. Error contacting Google servers. This is probably an authentication issue

查看:156
本文介绍了无法加载地图。错误接触谷歌服务器。这可能是一个身份验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索所有的日子,我无法找到答案......

I search all days and I can't find the answer...

万事俱备,但谷歌地图仍然无法片段,标签显示

everything is ready but google map still can't show on fragment with tab

我检查,我已经打开谷歌地图的Andr​​oid v2和右API_KEY

I check that I already turn on google map android v2 and right API_KEY

我不知道发生了什么事!

I have no idea what happened!

http://imgur.com/8NOuqOW

MainActivity.java:

MainActivity.java:

public class MainActivity extends FragmentActivity implements
        ActionBar.TabListener {

    SectionsPagerAdapter mSectionsPagerAdapter;

    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String titles[] = { this.getString(R.string.title_around),
                this.getString(R.string.title_map),
                this.getString(R.string.title_favorite),
                this.getString(R.string.title_achievement), };

        final ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mSectionsPagerAdapter = new SectionsPagerAdapter(
                getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager
                .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
                    @Override
                    public void onPageSelected(int position) {
                        actionBar.setSelectedNavigationItem(position);
                    }
                });

        for (int i = 0; i < titles.length; i++) {
            actionBar.addTab(actionBar.newTab().setText(titles[i])
                    .setTabListener(this));
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) {
        mViewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab,
            FragmentTransaction fragmentTransaction) {
    }

    @Override
    public void onTabReselected(ActionBar.Tab tab,
            FragmentTransaction fragmentTransaction) {
    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // TODO 在這邊決定哪個位置要給什麼 View(Fragment)
            Fragment fragment = null;
            // TODO 建議先在之前就初始化好 4 個 Fragment
            switch (position) {
            case 0:
                fragment = new AroundFragment();
                break;
            case 1:
                fragment = new MapsFragment();
                break;
            case 2:
                fragment = new FavoriteFragment();
                break;
            case 3:
                fragment = new AchievementFragment();
                break;
            default:
                break;
            }

            return fragment;
        }

        @Override
        public int getCount() {
            return 4;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            // TODO 在這邊決定每一個 View 的 title
            switch (position) {
            case 0:
                return getString(R.string.title_around);
            case 1:
                return getString(R.string.title_map);
            case 2:
                return getString(R.string.title_favorite);
            case 3:
                return getString(R.string.title_achievement);
            }
            return null;
        }
    }

}

MapsFragment.java:

MapsFragment.java:

public class MapsFragment extends Fragment{
    static final LatLng NKUT = new LatLng(23.979548, 120.696745);
    private GoogleMap map;
    SupportMapFragment mMapFragment;
    public MapsFragment() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.map_fragment,container, false);

        map = ((SupportMapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();

         mMapFragment = SupportMapFragment.newInstance();
         FragmentTransaction fragmentTransaction =
                 getFragmentManager().beginTransaction();
         fragmentTransaction.add(R.id.map,mMapFragment);
         fragmentTransaction.commit();

        return rootView;

    }
}

Map_fragment.xml

Map_fragment.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
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout> 

的Manifest.xml:

Manifest.xml:

<!-- Google Map -->
<permission
        android:name="com.jertt.yummymap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
<uses-permission android:name="com.jertt.yummymap.permission.MAPS_RECEIVE"/>
<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"/>
<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<!-- end -->
    <!-- Google Map API Key -->

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="key" />

    <!-- end -->

解决方法:

我找到了解决办法!

如果您使用专用的密钥库申请API_KEY。你不能上传和与Eclipse安装的应用程序。

If you use private keystore to apply API_KEY. You cannot upload and install application with eclipse.

您需要的文件上传.apk文件到您的设备自己安装吧!

You need to upload .apk file to your device by yourself and install it!

感谢Tarsem和SRIKANTH GR帮助!

Thanks Tarsem and srikanth gr help!!

推荐答案

这听起来像你有问题,你的 API_KEY 这是从谷歌的 API访问<得​​到/ STRONG>,所以验证您的 API_KEY 证书指纹包的名称

it sounds like you have problem with your API_KEY which is obtained from Google API Access ,so verify your API_KEY , certificate fingerprints and package name

也用这里面的&LT;舱单&GT;

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

和也验证了:&LT;元数据....&GT; 应该放在&lt;应用&GT; 标签

and also verify: <meta-data .... > should be inside <application> tag

PS。

1 同时加入尝试以下权限

1. Also try by adding following Permission

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

2 更改API密钥的Andr​​oidManifest.xml 后,必须 清除应用数据

要清除应用程序数据:

设置&gt;应用经理&gt;选择你的用途&gt;点击清除数据

必须卸载应用程序安装了! 注意不要重新安装除非你完全卸载,以便应用到清除其数据完全

Or Must Uninstall The Application before installing it ! Note Don't Re-install unless you Completely Uninstall the Application in order to clear its Data completely

这篇关于无法加载地图。错误接触谷歌服务器。这可能是一个身份验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆