Android Auto中Google Map显示空白问题技术求助
Android Auto 内置Google Maps空白问题排查求助
我想开发一款应用,在应用内通过地图显示从当前位置到目的地的路线,而非自动打开外部地图应用。尝试使用NavigationTemplate和MapWithContentTemplate两种模板后,在Android Auto中遇到Google Map显示空白的问题——两种模板下按钮、标题等UI组件均正常显示,但地图区域始终空白。
已完成操作
- 在AndroidManifest.xml中添加Google API Key;
- 创建Android Auto所需的服务和界面,分别测试NavigationTemplate和MapWithContentTemplate;
- 确认两种模板的非地图UI组件(按钮、标题等)均可正常显示;
- 查阅Google官方文档,但文档存在过时或废弃情况,未找到有效解决方案。
核心问题
- Android Auto中地图无法渲染,但其他UI组件(按钮、模板框架等)正常工作;
- Google Maps集成未按预期运行,不确定是配置错误、API废弃还是其他原因导致。
需解决的疑问
- 在Android Auto中使用Google Maps是否有遗漏的特定配置?
- Google Maps在Android Auto中有哪些已知问题或限制?
- 是否有替代NavigationTemplate或MapWithContentTemplate的方案或模板?
- Android Auto的Google Maps集成是否已废弃?若是,推荐的替代方案是什么?
相关代码
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
内容的提问来源于stack exchange,提问作者Paras Palli
相关产品推荐
相关产品推荐

