简体   繁体   English

Google Maps可以在Play商店中使用,但不能在dev中使用

[英]Google maps works in play store but doesn't work in dev

I'm currently working to improve an existing android app that maps different types of trees in an area. 我目前正在努力改善现有的android应用,该应用可在一个区域中映射不同类型的树木。

When the app is downloaded from the Google Play Store, the maps works fine. 从Google Play商店下载应用程序后,地图可以正常运行。 However when I'm working on it in Android Studios, it simply shows a grey screen. 但是,当我在Android Studios中进行处理时,它只会显示灰色屏幕。

I got an API key from google and put it in google_maps_api.xml 我从Google获得了API密钥,并将其放在google_maps_api.xml中

This is how I'm initializing the map: 这就是我初始化地图的方式:

if (savedInstanceState != null) {
        mMapFragment = (MapFragment) myFragmentManager.findFragmentByTag("map_tag");

        mMapFragment.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                mMap = googleMap;

                setUpMap();
            }
        });
        myFragment = (ControlClass) myFragmentManager.findFragmentByTag("control_tag");
        fragmentTransaction.commit();
        //mMap=mMapFragment.getMap();

    } else {

        mMapFragment = MapFragment.newInstance();
        fragmentTransaction.add(R.id.map, mMapFragment, "map_tag");

        useGPS = true;

        mMapFragment.setRetainInstance(true);
        myFragment = new ControlClass();
        fragmentTransaction.add(R.id.myfragment, myFragment, "control_tag");
        fragmentTransaction.commit();

        mMapFragment.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                mMap = googleMap;

                setUpMap();
                //handleNewLocation(lastKnownPosition);

            }
        });

    }

These are the permissions I'm using in my AndroidManifest: 这些是我在AndroidManifest中使用的权限:

<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="android.permission.READ_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" />

This is my layout for the maps activity: 这是我的地图活动布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/layout_root_view"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          tools:context=".MainActivity">

<LinearLayout
    android:id="@+id/myfragment"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"

    android:orientation="vertical"/>

<LinearLayout
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:orientation="vertical"/>

Any help would be greatly appreciated! 任何帮助将不胜感激!

So as it turns out, there are two versions of google_maps_api.xml, and my manifest was referring to the debug version, which still contained the previous api key. 事实证明,有google_maps_api.xml的两个版本,我的清单是指调试版本,该版本仍包含以前的api密钥。 Changing the key in the debug version of google_maps_api.xml fixed the problem. 在google_maps_api.xml的调试版本中更改密钥可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM