繁体   English   中英

Google地图未显示在android中

[英]Google maps not displaying in android

我正在我的应用程序中使用Google地图。 现在在android中,地图没有显示,尽管我已经检查了代码,一切正常。

我检查了这些步骤,它们工作正常:1)SHA代码正常。 2)我在应用程序中插入的密钥很好。 3)我已经为我的应用启用了地图API。

但是当我访问地图片段时,logcat显示以下内容:

06-22 18:57:47.380 8417-10561/ I/b: Sending API token request.
06-22 18:57:50.300 8417-10561/ E/b: Authentication failed on the server.
06-22 18:57:50.300 8417-10561/ E/Google Maps Android API: Authorization failure.  
  Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map.

06-22 18:57:50.300 8417-10561/ E/Google Maps Android API: 
                In the Google Developer Console (https://console.developers.google.com)
                   Ensure that the "Google Maps Android API v2" is enabled.
                   Ensure that the following Android Key exists:
                   API Key: AIz------------------------------------S
          Android Application (<cert_fingerprint>;<package_name>): SHA-1FingerPrint;PackageName

现在,我已经在互联网上搜索了有关此问题的信息,但尚未找到解决方案。 我经历了以下问题,但没有结果。

使用正确密钥的Google Maps V2无法在生产中使用

Google Maps Android API v2授权失败

这是我的地图活动代码:

private void setupWebView(View parentView) {
    loading = (ProgressBar) parentView.findViewById(R.id.loading);
    loading.setVisibility(View.GONE);
    if (googleMap == null) {
        googleMap = ((MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.mapf)).getMap();

    }
    setupMarkers(searchCenters.getText().toString());
}

private void setupMarkers(String searchFor) {
    googleMap.clear();
    if (searchFor == null || searchFor == "") {
        for (Center center : centers) {
            markers.add(
                    googleMap
                            .addMarker(new MarkerOptions()
                                    .position(new LatLng(center.getAddress().getLatitude(),
                                            center.getAddress().getLongitude()))
                                    .title(center.getName()).visible(true)));

        }
    } else {
        for (Center center : centers) {
            if (center.getName().toLowerCase().contains(searchFor.toLowerCase())) {
                markers.add(
                        googleMap.addMarker(new MarkerOptions()
                                .position(new LatLng(center.getAddress().getLatitude(),
                                        center.getAddress().getLongitude()))
                                .title(center.getName()).visible(true)));
            } else {
                markers.add(
                        googleMap.addMarker(new MarkerOptions()
                                .position(new LatLng(center.getAddress().getLatitude(),
                                        center.getAddress().getLongitude()))
                                .title(center.getName()).visible(false)));
            }
        }
    }

结果是这样的:

在此处输入图片说明

谁能帮我解决这个问题。 我知道在这里已经问过很多次了,但是我仍然找不到答案。

根据您提供的错误日志, Google Maps Android API: Authorization failure. 确保在Google API的控制台中激活Google Maps Android API v2服务,在生成API密钥时使用正确的程序包名称,确保您使用的是正确的密钥库文件来生成SHA1,并按照日志中的建议进行操作,确保Google Maps Android API v2已启用Google Maps Android API v2 ,请确保以下Android密钥存在。

我可以建议您通读Google Maps Android API的官方文档,该指南是将地图添加到Android应用程序的快速入门。 这些文档还讨论了如何获取Maps API Key ,还包括示例代码。

以下是一个示例代码,其中包含许多示例,这些示例说明了Google Maps Android API的用法: https : //github.com/googlemaps/android-samples

Android Studio有两个途径

app/src/debug/res/values/google_maps_api.xml
app/src/release/res/values/google_maps_api.xml

确保两者具有相同的google_maps_key

暂无
暂无

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

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