Google Map is Blank in Android Auto - Stack Overflow

admin2025-04-18  4

I want to create an app that displays the route from my current location to a destination using an in-app map, rather than opening an external maps application automatically.

Using NavigationTemplate

Using MapWithContentTemplate

I’m facing an issue where the Google Map is blank when using Android Auto.

Here’s what I’ve done so far:

  1. Added the Google API Key in the AndroidManifest.xml file.
  2. Created the necessary services and screens for Android Auto. Tried using both NavigationTemplate and MapWithContentTemplate.
  3. In both cases, the widgets (like buttons, titles, etc.) are visible, but the map itself is blank.
  4. I’ve checked the Google documentation, but it seems outdated or deprecated, and I couldn’t find a solution.

The Problem:

  1. The map is not rendering in Android Auto, even though the rest of the UI (widgets, templates, etc.) works fine.
  2. It seems like the Google Maps integration is not functioning as expected, and I’m unsure if this is due to a misconfiguration, deprecated APIs, or something else.

What I Need Help With:

  1. Is there a specific configuration I’m missing for Google Maps in Android Auto?
  2. Are there any known issues or limitations with Google Maps in Android Auto?
  3. Are there any alternative approaches or templates I should use instead of NavigationTemplate or MapWithContentTemplate?
  4. Is the Google Maps integration for Android Auto deprecated, and if so, what’s the recommended alternative?

Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=";>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    <uses-permission android:name="androidx.car.app.NAVIGATION_TEMPLATES"/>
    <uses-permission android:name="androidx.car.app.ACCESS_SURFACE" />

    <uses-feature android:name="android.hardware.sensorpass"
        android:required="true" />

    <uses-feature
        android:name="android.hardware.type.automotive"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:appCategory="audio"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Testing_navigation">

<!--    Important to show in Android Auto App-->
        <meta-data
            android:name="com.google.android.gms.car.application"
            android:resource="@xml/automotive_app_desc" />

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

        <meta-data
            android:name="androidx.car.app.minCarApiLevel"
            android:value="7"/>

        <service android:name=".MyNavigationService"
            android:exported="true">
            <intent-filter>
                <action android:name="androidx.car.app.CarAppService"/>
                <category android:name="androidx.car.app.category.NAVIGATION"/>
            </intent-filter>
        </service>

    </application>

</manifest>

Service:

class MyNavigationService : CarAppService() {
  override fun createHostValidator(): HostValidator {
    return if ((applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
      HostValidator.ALLOW_ALL_HOSTS_VALIDATOR
    } else {
      HostValidator.Builder(baseContext)
        .addAllowedHosts(R.array.hosts_allowlist_sample).build()
    }
  }

  override fun onCreateSession(): Session {
    return NavigationSession()
  }
}

class NavigationSession : Session() {
  override fun onCreateScreen(intent: Intent): Screen {

    // Navigation Screen
    return NavigationScreen(carContext)

    // Hello World Screen
    //    return HelloWorldScreen(carContext)
  }
}

Screen Template:

val row = Row.Builder().setTitle("Hello world!").build()
val paneBuilder = Pane.Builder().addRow(row)

val mapController = MapController.Builder()
  .build()

// Map Test Code 1
val template = NavigationTemplate.Builder()
  .setActionStrip(actionStrip)
  .setDestinationTravelEstimate(travelEstimate)
  .build()

// Map Test Code 2
val template = MapWithContentTemplate.Builder()
  .setLoading(false)
  .setContentTemplate(
    PaneTemplate.Builder(paneBuilder.build())
      .setTitle("Hello")
      .build()
  )
  .setActionStrip(actionStrip)
  .setMapController(mapController)
  .build()

return template

I want to create an app that displays the route from my current location to a destination using an in-app map, rather than opening an external maps application automatically.

Using NavigationTemplate

Using MapWithContentTemplate

I’m facing an issue where the Google Map is blank when using Android Auto.

Here’s what I’ve done so far:

  1. Added the Google API Key in the AndroidManifest.xml file.
  2. Created the necessary services and screens for Android Auto. Tried using both NavigationTemplate and MapWithContentTemplate.
  3. In both cases, the widgets (like buttons, titles, etc.) are visible, but the map itself is blank.
  4. I’ve checked the Google documentation, but it seems outdated or deprecated, and I couldn’t find a solution.

The Problem:

  1. The map is not rendering in Android Auto, even though the rest of the UI (widgets, templates, etc.) works fine.
  2. It seems like the Google Maps integration is not functioning as expected, and I’m unsure if this is due to a misconfiguration, deprecated APIs, or something else.

What I Need Help With:

  1. Is there a specific configuration I’m missing for Google Maps in Android Auto?
  2. Are there any known issues or limitations with Google Maps in Android Auto?
  3. Are there any alternative approaches or templates I should use instead of NavigationTemplate or MapWithContentTemplate?
  4. Is the Google Maps integration for Android Auto deprecated, and if so, what’s the recommended alternative?

Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    <uses-permission android:name="androidx.car.app.NAVIGATION_TEMPLATES"/>
    <uses-permission android:name="androidx.car.app.ACCESS_SURFACE" />

    <uses-feature android:name="android.hardware.sensor.compass"
        android:required="true" />

    <uses-feature
        android:name="android.hardware.type.automotive"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:appCategory="audio"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Testing_navigation">

<!--    Important to show in Android Auto App-->
        <meta-data
            android:name="com.google.android.gms.car.application"
            android:resource="@xml/automotive_app_desc" />

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

        <meta-data
            android:name="androidx.car.app.minCarApiLevel"
            android:value="7"/>

        <service android:name=".MyNavigationService"
            android:exported="true">
            <intent-filter>
                <action android:name="androidx.car.app.CarAppService"/>
                <category android:name="androidx.car.app.category.NAVIGATION"/>
            </intent-filter>
        </service>

    </application>

</manifest>

Service:

class MyNavigationService : CarAppService() {
  override fun createHostValidator(): HostValidator {
    return if ((applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
      HostValidator.ALLOW_ALL_HOSTS_VALIDATOR
    } else {
      HostValidator.Builder(baseContext)
        .addAllowedHosts(R.array.hosts_allowlist_sample).build()
    }
  }

  override fun onCreateSession(): Session {
    return NavigationSession()
  }
}

class NavigationSession : Session() {
  override fun onCreateScreen(intent: Intent): Screen {

    // Navigation Screen
    return NavigationScreen(carContext)

    // Hello World Screen
    //    return HelloWorldScreen(carContext)
  }
}

Screen Template:

val row = Row.Builder().setTitle("Hello world!").build()
val paneBuilder = Pane.Builder().addRow(row)

val mapController = MapController.Builder()
  .build()

// Map Test Code 1
val template = NavigationTemplate.Builder()
  .setActionStrip(actionStrip)
  .setDestinationTravelEstimate(travelEstimate)
  .build()

// Map Test Code 2
val template = MapWithContentTemplate.Builder()
  .setLoading(false)
  .setContentTemplate(
    PaneTemplate.Builder(paneBuilder.build())
      .setTitle("Hello")
      .build()
  )
  .setActionStrip(actionStrip)
  .setMapController(mapController)
  .build()

return template
Share Improve this question edited Feb 13 at 16:16 MrUpsidown 22.5k15 gold badges83 silver badges141 bronze badges asked Jan 30 at 5:11 Paras PalliParas Palli 2423 silver badges5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

When using the NavigationTemplate, MapWithContentTemplate, (or the other deprecated navigation templates), you are responsible for drawing the map yourself. Only the PlaceListMapTemplate (which can only be used by POI apps) handles drawing the map for you.

Since you're using Google Maps as your mapping provider and your app is a navigation app, you might be interested in using the Google Maps Android Auto SDK, which helps you draw the map yourself.

转载请注明原文地址:http://www.anycun.com/QandA/1744937388a89738.html