谷歌地图显示在模拟器上,但不显示在设备上 [英] Google Maps showing on emulator, but not on a device

查看:198
本文介绍了谷歌地图显示在模拟器上,但不显示在设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个基本的地图应用程序,这个应用程序可以通过AndroidStudio轻松实例化。

  package com.wayl.activities; 

导入android.os.Bundle;
导入android.support.v4.app.FragmentManager;
导入android.support.v7.app.AppCompatActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
导入com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
导入com.google.android.gms.maps.model.MarkerOptions;

import com.wayl.R;

public class MapsActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);

FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mapFragment =(SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
GoogleMap mMap = mapFragment.getMap();

//在悉尼添加标记并移动相机
LatLng sydney = new LatLng(-35,152);
mMap.addMarker(new MarkerOptions()。position(sydney).title(Marker near Sidney));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
[...]

如上所述,完全在AVD中,但没办法使它在真实设备上工作。它只显示一个空的地图占位符,还有丰富多彩的Google徽标。但没有标记,没有网格,没有按钮,没有别的。



为什么我认为它应该可以工作:


  • 网络,wifi,都可以,无论是在手机上还是在AVD中

  • OpenGL版本不应该是一个问题,我正在运行apk在
    Galaxy三星S3和Galaxy Note 4上。

  • 我将我的指纹放在调试版和发行版中, keytool 并与我的密钥库连接,因此键确定,您还可以查看参考图片,即使它说这是可选的。我将基础包和包含Maps活动的包仅用于确定。

  • 我等待了足够的时间用于应用程序获取位置,并指纹传播以防万一

  • Manifest具有检索粗略和精细位置的所有正确权限(请记住,AVD一切正常)


过去,我已经成功地在Android上开发地图。我记得每次经过4或5次试验和错误之后,我都可以实现这个过程。这次我不知道该怎么做更多。我正在播放S.O.了解我在哪里弄错了。

解决方案



在新的AndroidStudio示例中,包含关键字( google_maps_api.xml )的文件已放置到文件夹 app \src\debug\res\values 和另一个 app \src\release\res\values

当AndroidStudio向您显示所有布局,所有值文件等等,只有一个带有密钥的值文件,所以我没有注意到文件系统中实际上有两个文件,一个没有设置密钥!我甚至没有现在可以有不同的文件夹。



我在这方面挣扎了几天。每当我尝试创建一个简单的地图时,它都会发生变化,弹出窗口并让我失去时间。当你找到解决方案的时候,一切似乎都很明显,但同时也是令人沮丧的。



谢谢大家的帮助!我真的很感激。


I wrote a basic map application, the one that an be easily instantiated with AndroidStudio. The only difference the fragment is loaded inside another custom layout.

package com.wayl.activities;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import com.wayl.R;

public class MapsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        FragmentManager myFragmentManager = getSupportFragmentManager();
        SupportMapFragment mapFragment = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.map);
        GoogleMap mMap = mapFragment.getMap();

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-35, 152);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker near Sidney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
[...]

As said above, the app works perfectly in the AVD, but no way to make it work on a real device. It shows just an empty map placeholder, and also the colourful Google logo is there. But no markers, no grid, no buttons, nothing else.

Why I think it should work:

  • Network, wifi, are ok, both on the phone as in the AVD

  • The OpenGL version shouldn't be a problem, I'm running the apk both on a Galaxy Samsung S3, and on a Galaxy Note 4.

  • I placed my fingerprints both for debug and release version retrieved with keytool and connected with my keystore, so key it's OK, you can also see the reference image, even if it said this is optional. I put both the base package and the package containing the Maps activity just for being sure.

  • I waited enough time for the app to fetch the location, and for the fingerprint to propagate in case this would be needed.

  • Manifest has all the correct permission to retrieve coarse and fine location (remember in the AVD everything works perfectly)

I already succeed in the past to develop a map on Android. I remember each time after 4 or 5 trial and errors on the frustrating process I could achieve it. This time I don't know what to do more. I'm exploting S.O. to understand where I am mistaking.

解决方案

I finally came to a solution.

In the new AndroidStudio sample, the file with the key (google_maps_api.xml) has been placed to the folder app\src\debug\res\values, and another one in app\src\release\res\values!

While AndroidStudio show you all layouts, all values files, and so on, there is just one value file with the key, so I couldn't notice there were actually two files in the file system, one with the key not setup! I didn't even now there could be different folder for that.

I struggled few days on this. It happens every time I try to create a simple maps, something is changed, pop ups and make me lose time. When you catch the solution everything seems so obvious, but in the meanwhile it's really frustrating.

Thank you to everybody helped! I really appreciated.

这篇关于谷歌地图显示在模拟器上,但不显示在设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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