Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android MapsActivity根本没有加载地图_Android_Google Maps - Fatal编程技术网

Android MapsActivity根本没有加载地图

Android MapsActivity根本没有加载地图,android,google-maps,Android,Google Maps,我使用了默认代码来显示地图,但我想知道为什么它不起作用。我遵循了入门|谷歌地图API中显示的步骤。我已经为应用程序生成了一个API密钥,并对其进行了限制 这是我为MapsActivity.java编写的代码 public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; double LATITUDE, LONGITUDE; String MA

我使用了默认代码来显示地图,但我想知道为什么它不起作用。我遵循了入门|谷歌地图API中显示的步骤。我已经为应用程序生成了一个API密钥,并对其进行了限制

这是我为MapsActivity.java编写的代码

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

double LATITUDE, LONGITUDE;
String MARKER;

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

    Bundle lalo = getIntent().getExtras();
    if (lalo != null){
        LATITUDE = Double.valueOf(lalo.getString("LAT"));
        LONGITUDE = Double.valueOf(lalo.getString("LON"));
        MARKER = lalo.getString("MARKER");
    }

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    LatLng location = new LatLng(LATITUDE, LONGITUDE);
    mMap.addMarker(new MarkerOptions().position(location).title(MARKER));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(location));
}
}
以下是MapActivity的屏幕截图


请在这方面帮助我。

您是否正在使用名为“.debug”的调试版本的发布密钥?这也会引发这种情况。您可以显示日志以了解更多详细信息。

试试这个。它对我有用

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    

        SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.onCreate(savedInstanceState);
        mapFragment.onResume();
        mapFragment.getMapAsync(this);

    }

    @Override
    public void onResume() {
        mapFragment.onResume();
        super.onResume();
    }

    @Override
    public void onPause() {
        mapFragment.onPause();
        super.onPause();
    }

    @Override
    public void onDestroy() {
        mapFragment.onDestroy();
        super.onDestroy();
    }

    @Override
    public void onLowMemory() {
        mapFragment.onLowMemory();
        super.onLowMemory();
    }

我解决了IntelliJ Amiya让我去找logcat的问题。logcat说授权失败,然后我通过谷歌地图api控制台解决了这个问题。在那里,我看到我的API是正确的,但是SHA1密钥不正确,所以我从终端生成了一个并保存了它。我没有找到任何选项来启用谷歌地图Android API v2。但我不需要启用谷歌地图Android API v2。否则,我只是把正确的和新生成的SHA1键,并得到纠正


感谢大家提出的宝贵建议。

您的logcat返回了什么?请使用API键仔细检查步骤,如果出现问题,您将看到一个这样的空屏幕。另外,日志中是否有任何相关内容?您是否在清单中声明了元数据?您是否在开发人员控制台添加了正确的sha1密钥和包名。它显示授权失败: