You can customize the language and region settings used in your map by changing
the locale environment on your
Map, which
can affect the labels and behavior of the map based on the specified language
and country or territory.
See the coverage for Maps 3D SDK for iOS in the Maps coverage table.
Language localization
By default, the Maps 3D SDK for iOS uses the system locale configured on the
user's device (Locale.current) to determine which translation of the map to
display. You can override this default behavior by applying the SwiftUI
.environment(\.locale, ...) modifier to your
Map view, or
update the bound Locale state variable dynamically at runtime.
Setting the language affects the translation of political features, descriptors, and natural features—such as changing "Geneva" to "Genève" or "lake" to "lac"—and changes the direction that text is rendered for right-to-left scripts.
The Maps 3D SDK for iOS looks for localization preferences in the following order:
- SwiftUI environment: The
Localevalue passed to.environment(\.locale, ...)onMap. - Device settings: The system default locale configured on the iOS device.
The following example displays a
Map in
Chinese ("zh") and sets the region to China ("CN"):
import GoogleMaps3D
import SwiftUI
struct ContentView: View {
var body: some View {
Map(mode: .hybrid)
.environment(\.locale, Locale(identifier: "zh-CN"))
}
}
You can also update the language and region dynamically at runtime by binding
the environment locale to a @State property:
import GoogleMaps3D
import SwiftUI
struct LocalizationExampleView: View {
@State private var mapLocale: Locale = .current
var body: some View {
VStack {
Map(mode: .hybrid)
.environment(\.locale, mapLocale)
HStack {
Button("Français") {
mapLocale = Locale(identifier: "fr-FR")
}
Button("日本語") {
mapLocale = Locale(identifier: "ja-JP")
}
Button("中文") {
mapLocale = Locale(identifier: "zh-CN")
}
}
}
}
}
Region localization
Setting the region on the Locale passed to .environment(\.locale, ...) on
Map can
serve different map tiles or bias the app toward regionally appropriate results.
Setting the region also helps ensure that your app applies the regional
localization for the country or territory where the app is distributed.
To keep the user's device language while setting a specific region code (for
example, "JP"), construct a Locale using Locale.Components:
var components = Locale.Components(locale: Locale.current)
components.region = Locale.Region("JP")
let regionBiasedLocale = Locale(components: components)