我的应用显示空白地图

时间:2018-07-21 16:13:46

标签: android google-maps google-cloud-platform google-maps-android-api-2

我在我的应用程序中使用google map api。该地图运行正常,但现在它一片空白.Map仍在工作但未加载地图。我正在搜索答案几个小时,但未得到任何结果。在Google云端平台上创建了一个新的api,并放置了该api,但仍未加载地图。 任何可以帮助我的人。谢谢!

这是空白地图的屏幕截图。 Screenshot of map

07-21 21:28:59.573 18146-18265/com.example.har.firebaseauthenticationdemo 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.
07-21 21:28:59.575 18146-18265/com.example.har.firebaseauthenticationdemo 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: AIzaSyDWCP4m0DF57jZU4V8Yr7RFP2-DmhpgL34
                                                                                                        Android Application (<cert_fingerprint>;<package_name>): 0E:0E:68:77:05:BB:76:A3:5C:BC:62:F8:6A:AB:A5:5F:2A:7F:37:5F;com.example.har.firebaseauthenticationdemo
07-21 21:29:00.571 2256-2451/? E/Auth: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. Account: <ELLIDED:-895295850>, App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/login_manager
                                       fkq: Long live credential not available.
                                           at fkr.b(:com.google.android.gms@12529024@12.5.29 (040700-192802242):20)
                                           at fkr.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):50)
                                           at fjb.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):35)
                                           at gzf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):8)
                                           at gzf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):160)
                                           at gyf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):2)
                                           at gyc.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):17)
                                           at gyc.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):6)
                                           at cug.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):25)
                                           at cug.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):79)
                                           at cug.onTransact(:com.google.android.gms@12529024@12.5.29 (040700-192802242):8)
                                           at android.os.Binder.transact(Binder.java:627)
                                           at cwl.onTransact(:com.google.android.gms@12529024@12.5.29 (040700-192802242):3)
                                           at android.os.Binder.execTransact(Binder.java:697)
07-21 21:29:00.611 2256-3646/? E/Auth: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. Account: <ELLIDED:-895295850>, App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/login_manager
                                       fkq: Long live credential not available.
                                           at fkr.b(:com.google.android.gms@12529024@12.5.29 (040700-192802242):20)
                                           at fkr.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):50)
                                           at fjb.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):35)
                                           at gzf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):8)
                                           at gzf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):160)
                                           at gyf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):2)
                                           at gyc.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):17)
                                           at gyc.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):6)
                                           at cug.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):25)
                                           at cug.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):79)
                                           at cug.onTransact(:com.google.android.gms@12529024@12.5.29 (040700-192802242):8)
                                           at android.os.Binder.transact(Binder.java:627)
                                           at cwl.onTransact(:com.google.android.gms@12529024@12.5.29 (040700-192802242):3)
                                           at android.os.Binder.execTransact(Binder.java:697)
07-21 21:29:00.673 2256-3646/? E/Auth: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. Account: <ELLIDED:-895295850>, App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/login_manager
                                       fkq: Long live credential not available.
                                           at fkr.b(:com.google.android.gms@12529024@12.5.29 (040700-192802242):20)
                                           at fkr.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):50)
                                           at fjb.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):35)
                                           at gzf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):8)
                                           at gzf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):160)
                                           at gyf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):2)
                                           at gyc.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):17)
                                           at gyc.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):6)
                                           at cug.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):25)
                                           at cug.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):79)
                                           at cug.onTransact(:com.google.android.gms@12529024@12.5.29 (040700-192802242):8)
                                           at android.os.Binder.transact(Binder.java:627)
                                           at cwl.onTransact(:com.google.android.gms@12529024@12.5.29 (040700-192802242):3)
                                           at android.os.Binder.execTransact(Binder.java:697)
07-21 21:29:00.748 2426-18282/? E/ChromeSync: [Sync,SyncAdapter] Failed to sync.
                                              mbz: fgj: BadAuthentication
                                                  at mfy.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):5)
                                                  at mgm.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):42)
                                                  at mgn.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):22)
                                                  at mgn.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):73)
                                                  at mgn.b(:com.google.android.gms@12529024@12.5.29 (040700-192802242):7)
                                                  at mgl.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):41)
                                                  at nrg.onPerformSync(:com.google.android.gms@12529024@12.5.29 (040700-192802242):5)
                                                  at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:321)
                                               Caused by: fgj: BadAuthentication
                                                  at ffx.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):13)
                                                  at ffw.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):2)
                                                  at ffw.e(:com.google.android.gms@12529024@12.5.29 (040700-192802242):6)
                                                  at ffw.d(:com.google.android.gms@12529024@12.5.29 (040700-192802242):1)
                                                  at ffu.b(:com.google.android.gms@12529024@12.5.29 (040700-192802242):1)
                                                  at nms.b(Unknown Source:6)
                                                  at nlf.b(:com.google.android.gms@12529024@12.5.29 (040700-192802242):5)
                                                  at nlw.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):58)
                                                  at mfy.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):1)
                                                  at mgm.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):42) 
                                                  at mgn.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):22) 
                                                  at mgn.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):73) 
                                                  at mgn.b(:com.google.android.gms@12529024@12.5.29 (040700-192802242):7) 
                                                  at mgl.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):41) 
                                                  at nrg.onPerformSync(:com.google.android.gms@12529024@12.5.29 (040700-192802242):5) 
                                                  at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:321) 
07-21 21:29:03.389 1599-1612/? E/memtrack: Couldn't load memtrack module
07-21 21:29:05.559 1599-1612/? E/memtrack: Couldn't load memtrack module
07-21 21:29:05.574 1599-1612/? E/memtrack: Couldn't load memtrack module
07-21 21:29:12.866 2256-18310/? E/Auth: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. Account: <ELLIDED:-895295850>, App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/experimentsandconfigs
                                        fkq: Long live credential not available.
                                            at fkr.b(:com.google.android.gms@12529024@12.5.29 (040700-192802242):20)
                                            at fkr.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):50)
                                            at fjb.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):35)
                                            at gzf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):8)
                                            at gzf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):160)
                                            at gyf.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):2)
                                            at gyc.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):17)
                                            at gyc.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):6)
                                            at cug.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):25)
                                            at cug.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):79)
                                            at ffx.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):6)
                                            at ffw.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):2)
                                            at ffw.e(:com.google.android.gms@12529024@12.5.29 (040700-192802242):6)
                                            at ffu.f(:com.google.android.gms@12529024@12.5.29 (040700-192802242):3)
                                            at ffu.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):4)
                                            at ffu.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):7)
                                            at aenk.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):22)
                                            at aenm.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):130)
                                            at aenm.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):243)
                                            at aenm.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):404)
                                            at com.google.android.gms.phenotype.sync.HeterodyneSyncTaskChimeraService.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):66)
                                            at com.google.android.gms.phenotype.sync.HeterodyneSyncTaskChimeraService.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):20)
                                            at ulu.run(:com.google.android.gms@12529024@12.5.29 (040700-192802242):1)
                                            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                            at java.lang.Thread.run(Thread.java:764)
07-21 21:29:12.884 2256-18310/? E/HeterodyneSyncTaskChime: Failed to get auth token: User intervention required. Notification has been pushed. -- metadata{ service_id: 51 }
                                                           fgk: User intervention required. Notification has been pushed.
                                                               at ffu.f(:com.google.android.gms@12529024@12.5.29 (040700-192802242):10)
                                                               at ffu.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):4)
                                                               at ffu.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):7)
                                                               at aenk.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):22)
                                                               at aenm.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):130)
                                                               at aenm.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):243)
                                                               at aenm.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):404)
                                                               at com.google.android.gms.phenotype.sync.HeterodyneSyncTaskChimeraService.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):66)
                                                               at com.google.android.gms.phenotype.sync.HeterodyneSyncTaskChimeraService.a(:com.google.android.gms@12529024@12.5.29 (040700-192802242):20)
                                                               at ulu.run(:com.google.android.gms@12529024@12.5.29 (040700-192802242):1)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                               at java.lang.Thread.run(Thread.java:764)

3 个答案:

答案 0 :(得分:0)

制作新应用。一个星期前,我在两天后制作了一个webview应用,但webview没有加载任何内容,因此请新建一个。

答案 1 :(得分:0)

  

确保已启用“ Google Maps Android API v2”。

  • 转到Google Console API,然后搜索Maps for android API。并确保已启用。
  

确保存在以下Android密钥:

  • 转到Google控制台凭据管理器。并添加用于调试和发布的Android API密钥。检查Google Doc了解更多详细信息。

更新1

  • 从您的logcat中获取。
  

07-21 21:28:59.573   18146-18265 / com.example.har.firebaseauthenticationdemo E / Google地图   Android API:授权失败。

请参见https://developers.google.com/maps/documentation/android-api/start,了解如何正确设置地图。

更新2

build.gradle

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            resValue "string", "google_maps_api_key", "Release_API_KEY"
        }
        debug {
//          KL MBP debug Key
            resValue "string", "google_maps_api_key", "DEBUG_API_KEY"
//          KL Old Machine debug Key
//            resValue "string", "google_maps_api_key", "DEBUG_API_KEY"
        }
    }

AndroidManifest.xml

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

    <uses-library
        android:name="com.google.android.maps"
        android:required="true" />

更新3

获取SHA1以用于生成API密钥

  • 对于Linux或macOS,打开终端窗口并输入以下内容:
  

macOS和Linux:~/.android/

 keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android 
  • 对于Windows Vista和Windows 7,运行:
  

Windows Vista和Windows 7:

C:\Users\your_user_name\.android\ List the SHA-1 fingerprint:

keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

更新4

在Android Studio中,您可以找到所有应用程序签名信息,而无需任何控制台命令:

  1. 打开您的项目
  2. 在右侧面板上单击Gradle
  3. 在Gradle项目面板中打开文件夹:您的项目->任务-> Android
  4. 运行signingReport任务(双击),您将在Gradle控制台中看到结果(密钥库路径,SHA1,MD5等)。

答案 2 :(得分:0)

1。获取Google Maps API密钥

https://developers.google.com/maps/documentation/android-sdk/signup?authuser=1

2。将此API密钥放置在strings.xml或Android Manifest中

AndroidManifest.xml

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_maps_key" />

string.xml

<string name="google_maps_key">YOUR_API_KEY</string>

3。将SupportMapFragment放入所需的xml

<fragment
   android:id="@+id/placesMap"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_marginTop="8dp"
   android:layout_marginBottom="8dp"
   android:tag="@string/tag_places_search_map"
   class="com.google.android.gms.maps.SupportMapFragment" />

最后是Activity

class SampleActivity :
        GoogleMap.OnMarkerClickListener,
        GoogleMap.OnMarkerDragListener,
        GoogleMap.OnInfoWindowClickListener,
        GoogleMap.OnInfoWindowLongClickListener,
        GoogleMap.OnInfoWindowCloseListener,
        OnMapAndViewReadyListener.OnGlobalLayoutAndMapReadyListener,
        GoogleMap.OnMapLoadedCallback
{
    private lateinit var map: GoogleMap

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val mapFragment = supportFragmentManager.findFragmentById(R.id.placesMap) as SupportMapFragment
        OnMapAndViewReadyListener(mapFragment, this)
    }

    internal inner class CustomInfoWindowAdapter : GoogleMap.InfoWindowAdapter {

        // These are both view groups containing an ImageView with id "badge" and two
        // TextViews with id "title" and "snippet".
        private val window: View = layoutInflater.inflate(R.layout.custom_info_window, null)
        private val contents: View = layoutInflater.inflate(R.layout.custom_info_contents, null)

        override fun getInfoWindow(marker: Marker): View? {
             render(marker, window)
            return window
        }

        override fun getInfoContents(marker: Marker): View? {
            render(marker, contents)
            return contents
        }

        private fun render(marker: Marker, view: View) {

            // Set the title and snippet for the custom info window
            val title: String? = marker.title
            val titleUi = view.findViewById<TextView>(R.id.title)

            if (title != null) {
                // Spannable string allows us to edit the formatting of the text.
                titleUi.text = SpannableString(title).apply {
                    setSpan(ForegroundColorSpan(resources.getColor(R.color.text_grey_heading)), 0, length, 0)
                }
            } else {
                titleUi.text = ""
            }

            val snippet: String? = marker.snippet
            val snippetUi = view.findViewById<TextView>(R.id.snippet)
            snippetUi.text = snippet
        }
    }

    override fun onMarkerClick(marker: Marker?): Boolean {
        marker?.zIndex = marker?.zIndex?.plus(1.0f)!!
        val handler = Handler()
        val start = SystemClock.uptimeMillis()
        val duration = 1500

        val interpolator = BounceInterpolator()

        handler.post(object : Runnable {
            override fun run() {
                val elapsed = SystemClock.uptimeMillis() - start
                val t = Math.max(
                        1 - interpolator.getInterpolation(elapsed.toFloat() / duration), 0f)
                marker?.setAnchor(0.5f, 1.0f + 2 * t)

                // Post again 16ms later.
                if (t > 0.0) {
                    handler.postDelayed(this, 16)
                }
            }
        })
        return false
    }

    override fun onMarkerDragEnd(p0: Marker?) {
    }

    override fun onMarkerDragStart(p0: Marker?) {
    }

    override fun onMarkerDrag(p0: Marker?) {
    }

    override fun onInfoWindowClick(marker : Marker) {
        //Toast.makeText(this, "Click Info Window", Toast.LENGTH_SHORT).show()
    }

    override fun onInfoWindowClose(marker : Marker) {
        //Toast.makeText(this, "Close Info Window", Toast.LENGTH_SHORT).show()
    }

    override fun onInfoWindowLongClick(marker : Marker) {
        //Toast.makeText(this, "Info Window long click", Toast.LENGTH_SHORT).show()
    }

    override fun onMapLoaded() {
        addMarkersToMap()
    }

    override fun onMapReady(googleMap: GoogleMap?) {
        map = googleMap ?: return

        with(map) {
            // Hide the zoom controls as the button panel will cover it.
            uiSettings.isZoomControlsEnabled = false

            // Setting an info window adapter allows us to change the both the contents and
            // look of the info window.
            setInfoWindowAdapter(CustomInfoWindowAdapter())

            // Set listeners for marker events.  See the bottom of this class for their behavior.
            setOnMarkerClickListener(this@SampleActivity)
            setOnInfoWindowClickListener(this@SampleActivity)
            setOnMarkerDragListener(this@SampleActivity)
            setOnInfoWindowCloseListener(this@SampleActivity)
            setOnInfoWindowLongClickListener(this@SampleActivity)
            setOnMapLoadedCallback(this@SampleActivity)

            // Override the default content description on the view, for accessibility mode.
            // Ideally this string would be localised.
            setContentDescription("Map with lots of markers.")
        }
    }

    fun addMarkersToMap(data: List<Places>) {
        // create bounds that encompass every location we reference
        val boundsBuilder = LatLngBounds.Builder()

        data.map { place -> boundsBuilder.include(LatLng(place.venue.location.lat!!,place.venue.location.lng)) }
        val bounds = boundsBuilder.build()
        with(map){
            moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50))
        }
        val list : MutableList<PlaceDetails> = mutableListOf<PlaceDetails>()
        for (place in data){
            list.add(PlaceDetails(place.id,LatLng(place.venue.location.lat!!,place.venue.location.lng),
                    place.venue.name,
                    place.getDistance()))
        }

        //add Seattle center as marker on map
        var seattlePD : PlaceDetails = PlaceDetails(TConstants.SEATTLLE_ID,
            LatLng(resources.getString(R.string.seattle_lat).toDouble(), resources.getString(R.string.seattle_long).toDouble()),
                "Seattle","Seattle Center",
                BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN))
        map.addMarker(MarkerOptions()
                .position(seattlePD.position)
                .title(seattlePD.title)
                .snippet(seattlePD.snippet)
                .icon(seattlePD.icon)
                .infoWindowAnchor(seattlePD.infoWindowAnchorX, seattlePD.infoWindowAnchorY)
                .draggable(seattlePD.draggable)
                .zIndex(seattlePD.zIndex))

        for (placeDetails in list){
            var marker = map.addMarker(MarkerOptions()
                    .position(placeDetails.position)
                    .title(placeDetails.title)
                    .snippet("Distance : "+placeDetails.snippet)
                    .icon(placeDetails.icon)
                    .infoWindowAnchor(placeDetails.infoWindowAnchorX, placeDetails.infoWindowAnchorY)
                    .draggable(placeDetails.draggable)
                    .zIndex(placeDetails.zIndex))
            searchViewModel.markerTracker.put(marker.id,placeDetails)
        }
    }
}