新版地图渲染程序
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
升级版地图渲染程序自 Maps SDK for Android 18.2.0 版起提供。此版本渲染程序带来了许多的改进,包括对云端地图样式设置的支持。
新版渲染程序具有以下优势:
- 提供了云端地图样式设置功能。
- 可进行高级多段线自定义操作。
- 减少了网络负载、处理需求和内存消耗。
- 通过改进手势处理获得更好的动画效果,实现更顺畅的平移和缩放操作。
- 更流畅的过渡和定位清晰的地图标签。
- 更稳定、更出色的用户体验。
发布时间表
2024 年 3 月,Google 开始自动更新设备上所有已部署的应用,以便使用升级版渲染程序。自动更新将在未来几个月内根据具体设备情况逐步进行,这意味着最终用户设备将在更新期间的不同时间进行更新。
自动更新适用于在符合最低设备要求的设备上运行的所有应用,无论应用使用的是哪个版本的 Maps SDK for Android。
自动更新不适用于以下应用:
更改默认渲染程序后会发生什么?
Maps SDK for Android 18.2.0 版发布后,升级版渲染程序将成为默认渲染程序。如要使用升级版渲染程序,您可以使用新版 SDK 构建新应用或重新构建任何现有应用。或者,您也可以等到 Google 自动更新您部署的应用。
升级后,您的应用就可以利用升级版渲染程序中提供的所有新功能和优势。
但是,如果您决定选择不进行更改,您的应用将继续使用旧版渲染程序。请参阅选择停用升级版渲染程序,了解有关如何选择停用的代码示例。
支持的设备
自动更新适用于符合以下条件的所有设备,无论应用使用的是哪个版本的 Maps SDK for Android:
- Android 5.0(API 级别 21)或更高版本
- 使用的是 Google Play 服务 21.39.14 或更高版本
符合如下任一条件的设备将继续使用旧版渲染程序:使用 Android 4.4W(API 级别 20)及更低版本;或者使用 Google Play 服务 21.39.13 或更低版本。
选择停用升级版渲染程序
如有必要,您可以明确选择停用升级版渲染程序,以便在应用中使用旧版渲染程序。
如要选择停用,请执行以下操作:
您的代码必须在创建任何 MapView、MapFragment 或 SupportMapFragment 前调用 MapsInitializer.initialize()
。我们建议在 onCreate
中针对应用的 Application 或 Activity 进行该项调用,然后再设置其内容视图。
以下示例展示了如何调用 MapsInitializer.initialize()
来停用升级版渲染程序,继续使用旧版渲染程序。
Kotlin
import com.google.android.gms.maps.MapsInitializer
import com.google.android.gms.maps.MapsInitializer.Renderer
import com.google.android.gms.maps.OnMapsSdkInitializedCallback
internal class MapRendererOptInApplication : Application(), OnMapsSdkInitializedCallback {
override fun onCreate() {
super.onCreate()
MapsInitializer.initialize(applicationContext, Renderer.LEGACY, this)
}
override fun onMapsSdkInitialized(renderer: MapsInitializer.Renderer) {
when (renderer) {
Renderer.LATEST -> Log.d("MapsDemo", "The latest version of the renderer is used.")
Renderer.LEGACY -> Log.d("MapsDemo", "The legacy version of the renderer is used.")
}
}
}
Java
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.MapsInitializer.Renderer;
import com.google.android.gms.maps.OnMapsSdkInitializedCallback;
class MapRendererOptInApplication extends Application implements OnMapsSdkInitializedCallback {
@Override
public void onCreate() {
super.onCreate();
MapsInitializer.initialize(getApplicationContext(), Renderer.LEGACY, this);
}
@Override
public void onMapsSdkInitialized(MapsInitializer.Renderer renderer) {
switch (renderer) {
case LATEST:
Log.d("MapsDemo", "The latest version of the renderer is used.");
break;
case LEGACY:
Log.d("MapsDemo", "The legacy version of the renderer is used.");
break;
}
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-05-10。
[null,null,["最后更新时间 (UTC):2024-05-10。"],[[["\u003cp\u003eThe Maps SDK for Android now features an upgraded map renderer with cloud-based styling and improved performance.\u003c/p\u003e\n"],["\u003cp\u003eAutomatic updates to the new renderer are complete for eligible apps, enhancing user experience with smoother interactions and better visuals.\u003c/p\u003e\n"],["\u003cp\u003eDevices require Android 5.0 (API level 21) or later and Google Play services version 21.39.14 or later to use the upgraded renderer.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can opt out of the upgraded renderer and use the legacy renderer, although the legacy renderer is deprecated and will be decommissioned in March 2025.\u003c/p\u003e\n"],["\u003cp\u003eOpting out requires explicit initialization with \u003ccode\u003eMapsInitializer\u003c/code\u003e and specifying \u003ccode\u003eRenderer.LEGACY\u003c/code\u003e before creating any map views or fragments.\u003c/p\u003e\n"]]],["The Maps SDK for Android version 18.2.0 introduced an upgraded map renderer, which was automatically rolled out to all applicable apps by March 2024. This new renderer offers cloud-based styling, advanced polyline customization, reduced resource usage, and improved performance. Devices must use Android 5.0+ and Google Play services 21.39.14+. Apps can opt-out of the upgrade to the legacy renderer by upgrading the Maps SDK to v18.0 or greater, and calling `MapsInitializer.initialize()` with `Renderer.LEGACY`. The legacy renderer will be decommissioned in March 2025.\n"],null,["An upgraded map renderer is available as of version 18.2.0 of the\nMaps SDK for Android. This renderer brings many improvements, including support for\nCloud-based maps styling.\n\nThe new renderer provides the following benefits:\n\n- [Cloud-based maps styling](/maps/documentation/android-sdk/cloud-based-map-styling) features are available with the new renderer.\n- [Advanced Polyline Customizations](/maps/documentation/android-sdk/shapes#polyline-customization) are available with the new renderer.\n- Reduced network load, processing demand, and memory consumption.\n- Improved gesture handling for better animations, plus smoother panning and zooming.\n- More fluid transitions and clearly positioned map labels.\n- A more stable and improved user experience.\n\nAutomatic update status\n\nIn March of 2024, Google began automatically updating all deployed apps to use\nthe upgraded renderer. Automatic updates have been applied to all apps running\non devices that meet the [minimum device requirements](#supported-devices),\nregardless of the version of the Maps SDK for Android used by the app. This rollout\nis now complete.\n\nThe automatic updates did not apply to:\n\n- Apps that have already updated to use the upgraded renderer.\n\n- Apps that have explicitly [opted out](#opt-out) of the upgrade.\n\n- Apps running on devices that don't meet the [minimum device\n requirements](#supported-devices).\n\nSupported devices\n\nTo use the upgraded map renderer, devices must meet these criteria:\n\n- Android 5.0 (API level 21) or later\n- Using Google Play services version 21.39.14 or later\n\nDevices using Android 4.4W (API level 20) and earlier or using Google Play\nservices versions 21.39.13 or earlier continue to use the legacy renderer.\n\nOpt-out of using the upgraded renderer\n\nIf necessary, you can explicitly opt-out of using the upgraded renderer to use\nthe legacy renderer in your app.\n| **Important:** The legacy renderer is deprecated and is scheduled for decommissioning in April 2025. Follow the legacy renderer's decommissioning progress in public issue [404999856](https://issuetracker.google.com/issues/404999856). After the legacy renderer is decommissioned, you will no longer be able to opt-out of using the upgraded renderer. However, apps running on devices that don't meet the [minimum requirements](#supported-devices) for the new renderer will continue to function with the legacy renderer.\n\nTo opt-out:\n\n- [Upgrade](/maps/documentation/android-sdk/versions) Maps SDK for Android to\n v18.0 or greater.\n\n- Update your code to explicitly import [MapsInitializer](/android/reference/com/google/android/gms/maps/MapsInitializer)\n and\n [MapsInitializer.Renderer](/android/reference/com/google/android/gms/maps/MapsInitializer.Renderer).\n\n- Update your code to call\n [`MapsInitializer.initialize()`](/android/reference/com/google/android/gms/maps/MapsInitializer#initialize(android.content.Context,%20com.google.android.gms.maps.MapsInitializer.Renderer,%20com.google.android.gms.maps.OnMapsSdkInitializedCallback)),\n passing `Renderer.LEGACY` to opt-out and use the legacy renderer.\n\n- Use [OnMapsSdkInitializedCallback](/android/reference/com/google/android/gms/maps/OnMapsSdkInitializedCallback)\n to determine which version of the renderer was returned.\n\nYour code must call\n[`MapsInitializer.initialize()`](/android/reference/com/google/android/gms/maps/MapsInitializer)\nbefore any\n[MapView](/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/MapView),\n[MapFragment](/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/MapFragment),\nor\n[SupportMapFragment](/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/SupportMapFragment)\nhas been created. We recommend calling this in `onCreate` for your app's\n[Application](https://developer.android.com/reference/android/app/Application#onCreate()),\nor\n[Activity](https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle,%20android.os.PersistableBundle)),\nbefore its content view is set.\n\nThe following example shows how to call `MapsInitializer.initialize()` to\nopt-out to use the legacy map renderer. \n\nKotlin \n\n```kotlin\nimport com.google.android.gms.maps.MapsInitializer\nimport com.google.android.gms.maps.MapsInitializer.Renderer\nimport com.google.android.gms.maps.OnMapsSdkInitializedCallback\n\ninternal class MapRendererOptInApplication : Application(), OnMapsSdkInitializedCallback {\n override fun onCreate() {\n super.onCreate()\n MapsInitializer.initialize(applicationContext, Renderer.LEGACY, this)\n }\n\n override fun onMapsSdkInitialized(renderer: MapsInitializer.Renderer) {\n when (renderer) {\n Renderer.LATEST -\u003e Log.d(\"MapsDemo\", \"The latest version of the renderer is used.\")\n Renderer.LEGACY -\u003e Log.d(\"MapsDemo\", \"The legacy version of the renderer is used.\")\n }\n }\n}\n```\n\nJava \n\n```java\nimport com.google.android.gms.maps.MapsInitializer;\nimport com.google.android.gms.maps.MapsInitializer.Renderer;\nimport com.google.android.gms.maps.OnMapsSdkInitializedCallback;\n\nclass MapRendererOptInApplication extends Application implements OnMapsSdkInitializedCallback {\n\n @Override\n public void onCreate() {\n super.onCreate();\n MapsInitializer.initialize(getApplicationContext(), Renderer.LEGACY, this);\n }\n\n @Override\n public void onMapsSdkInitialized(MapsInitializer.Renderer renderer) {\n switch (renderer) {\n case LATEST:\n Log.d(\"MapsDemo\", \"The latest version of the renderer is used.\");\n break;\n case LEGACY:\n Log.d(\"MapsDemo\", \"The legacy version of the renderer is used.\");\n break;\n }\n }\n}\n```"]]