How to create map IDs

  • A map ID is a unique identifier that represents a single Google Map instance, used to manage, style, or enable features on maps across various platforms (JavaScript, Android, iOS, Static Maps).

  • Map IDs are created within the Google Cloud console on the Map Management page, requiring Editor or Owner permissions.

  • To use a map ID, you need to integrate it into your application code based on the specific platform (JavaScript, Android, iOS, or Static Maps) you're working with, following the provided instructions.

  • Cloud-based map styling allows you to associate a style with your map ID, impacting its visual appearance on the map.

  • Map IDs can be added to the Maps Static API by appending the 'map_id' URL parameter, and a new digital signature might be required for existing URLs.

A map ID is a unique identifier that represents Google Map styling and configuration settings that are stored in Google Cloud. You use map IDs to enable features or manage or style maps on your websites and in your applications. You can create map IDs for each platform you need--JavaScript, Android, iOS, or Static maps--in your Google Cloud console project on the Map Management page.

For more details and features that use map IDs, see Map ID overview.

Required permissions

To create or manage any map IDs in your project, you must use a principal with the appropriate role-level permissions, Editor or Owner, on the Cloud console IAM page for the project. For details, see IAM basic and predefined roles reference.

Create map IDs

Create map IDs in the Cloud console following these steps:

  1. Sign in to and open a Cloud console project with the required permissions.

  2. In the Cloud console, go to the Maps Management page.

  3. Click Create map ID.

    Create New Map ID

  4. On the Create new map ID page, do the following:

    1. For Name, give the map ID a name.
    2. Optional: For Description, describe what the map ID is used for.
    3. For Map type, select the platform on which you plan to use the map ID. If you choose JavaScript, also choose a Raster (the default) or Vector map type. For more information on vector maps, see Vector Maps.
    4. Click Save to show your new map ID.

Associate a map ID to a map style

If you are using cloud-based maps styling, you associate a map style with your map ID. For details, see Associate your style to a map ID.

Add the map ID to your app

Android

Add your map ID through a <fragment> element in the activity's layout file, by using the MapView class, or programmatically using the GoogleMapOptions class.

For example, assume you created a map ID that is stored as a string value named map_id in res/values/strings.xml:

<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<stringname="map_id">MAP_ID</string>
</resources>

For maps added through a <fragment> element in the activity's layout file, all map fragments that should have the custom style must specify the map ID in the map:mapId attribute:

<fragmentxmlns:map="http://schemas.android.com/apk/res-auto"
map:name="com.google.android.gms.maps.SupportMapFragment"
...
map:mapId="@string/map_id"/>

You can also use the map:mapId attribute of the MapView class to specify a map ID:

<com.google.android.gms.maps.MapView
xmlns:map="http://schemas.android.com/apk/res-auto"
....
map:mapId="@string/map_id"/>

To specify a map ID programmatically, pass it to a MapFragment instance using the GoogleMapOptions class:

Java

MapFragmentmapFragment=MapFragment.newInstance(
newGoogleMapOptions()
.mapId(getResources().getString(R.string.map_id)));

Kotlin

valmapFragment=MapFragment.newInstance(
GoogleMapOptions()
.mapId(resources.getString(R.string.map_id))
)

In Android Studio, build and run your app as you normally would. Custom styles configured in the first step are applied to all maps with the specified map ID.

Android 3D

Set the mapId String property onto the Map3DOptions either programmatically or using layout attributes. Map3DOptions are provided to the Map3DView object during instantiation and can't be changed after Map3DView is constructed.

Developers can optionally implement a new OnMapIdErrorListener to be notified and react to an invalid or not-found map ID.

Add a map ID, creating the map programmatically, and set an OnMapIdErrorListener:

importcom.google.android.gms.maps3d.GoogleMap3D
importcom.google.android.gms.maps3d.Map3DOptions
importcom.google.android.gms.maps3d.Map3DView
importcom.google.android.gms.maps3d.OnMap3DViewReadyCallback
importcom.google.android.gms.maps3d.model.Map3DMode
classMainActivity:Activity(),OnMap3DViewReadyCallback,OnMapIdError{
funonCreate(...){
valmap3DOptions=Map3DOptions(mapMode=Map3DMode.HYBRID,mapId="MAP_ID")
valmap3DView=Map3DView(context,map3DOptions)
map3DView.getMap3dViewAsync(this)
}
overridefunonMap3DViewReady(googleMap3D:GoogleMap3D){
googleMap3D.setMapIdErrorListener(
object:OnMapIdErrorListener{
overridefunonMapIdError(){
// Handle error event.
}
}
)
}
}

Add a map ID using layout attributes:

<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map3d="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"android:layout_height="match_parent">
<com.google.android.gms.maps3d.Map3DView
android:id="@+id/map3dView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
map3d:mode="hybrid"
map3d:mapId="MAP_ID"/>
</LinearLayout>

iOS

To instantiate a map using a map ID, do the following:

  1. Create a GMSMapID with the map ID string from Cloud console.
  2. Create a GMSMapView specifying the map ID you just created.

Swift

letcamera=GMSCameraPosition(latitude:47.0169,longitude:-122.336471,zoom:12)
letmapID=GMSMapID(identifier:"MAP_ID")
letmapView=GMSMapView(frame:.zero,mapID:mapID,camera:camera)
self.view=mapView

Objective-C

GMSCameraPosition*camera=[GMSCameraPositioncameraWithLatitude:47.0169
longitude:-122.336471
zoom:12];
GMSMapID*mapID=[GMSMapIDmapIDWithIdentifier:@"MAP_ID"];
GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZeromapID:mapIDcamera:camera];
self.view=mapView;

If you are using your own map ID, you can set your map ID in the Cloud console to have a new style at any time, and that style will be reflected on your map view automatically for you and users within about six hours.

If you want to see the changes immediately, you can close out and restart your app by exiting the app, forcing a quit of the app from the recently-used apps list, and then reopening it. The updated map will then be visible.

iOS 3D

iOS developers can set a new style modifier on Map. This modifier accepts a map ID and optionally a closure to be invoked when the map ID is invalid or not found.

importSwiftUI
importGoogleMaps3D
structContentView:View{
init(){
Map.apiKey="YOUR_API_KEY"
}
varbody:someView{
Map(initialCamera:.init(
latitude:0.0,
longitude:0.0,
),
mode:.hybrid
)
.style(
with:"MAP_ID",
error:{
// Handle styling error.
}
)
// Could also use trailing closure syntax
// .style(with: "MAP_ID") {
// // Handle styling error.
// }
}
}

JavaScript

To create a map with a map ID in your application code:

  1. If you are already customizing your map with embedded JSON code, remove the styles property from your MapOptions object; otherwise, skip this step.

  2. Add a map ID to the map using the mapId property. For example:

map=newgoogle.maps.Map(document.getElementById('map'),{
center:{lat:-34.397,lng:150.644},
zoom:8,
mapId:'MAP_ID'
});

Javascript 3D

To create a map with a map ID in your application, add a map ID to the map using the mapId property. For example:

asyncfunctioninit(){
const{Map3DElement}=awaitgoogle.maps.importLibrary('maps3d');
constmap=newMap3DElement({
center:{
lat:37.75183154601466,
lng:-119.52369070507672,
altitude:2200,
},
tilt:67.5,
heading:108.94057782079429,
range:6605.57279990986,
mapId:'bcce776b92de1336e22c569f',// Styles are associated with map IDs.
mode:'HYBRID',
});
document.body.append(map);
}
voidinit();

Maps Static

To add a map ID to a new or existing map that uses one of our web-service APIs, append the map_id URL parameter and set it to your map ID. This example shows adding a map ID to a map using Maps Static API.

<img src="https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284&key=YOUR_API_KEY&map_id=MAP_ID&signature=YOUR_SIGNATURE" />

A map centered on the Brooklyn Bridge in New York City, NY, US with map controls in the lower right corner. The map displays custom styling on the roads, water, and land.

If you have a digital signature in your Maps Static URL before adding your map ID, you will need to create and add a new digital signature after adding your map ID. When generating your new URL signing secret, remember to remove your previous digital signature from the URL.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026年09月01日 UTC.