Les superpositions sont des objets qui, sur une carte, sont liés aux coordonnées de latitude/longitude. Elles se déplacent donc lorsque vous faites glisser une carte ou effectuez un zoom. Si vous souhaitez placer une image sur une carte, vous pouvez utiliser un objet GroundOverlay.
Pour en savoir plus sur les autres types de superposition, consultez Dessiner sur la carte.
Ajouter une superposition au sol
Le constructeur d'une GroundOverlay spécifie l'URL d'une image et les LatLngBounds de l'image en tant que paramètres. L'image est affichée sur la carte dans les limites définies et adaptée en utilisant la projection de la carte.
TypeScript
// This example uses a GroundOverlay to place an image on the map// showing an antique map of Newark, NJ.lethistoricalOverlay;functioninitMap():void{constmap=newgoogle.maps.Map(document.getElementById("map")asHTMLElement,{zoom:13,center:{lat:40.74,lng:-74.18},});constimageBounds={north:40.773941,south:40.712216,east:-74.12544,west:-74.22655,};historicalOverlay=newgoogle.maps.GroundOverlay("https://storage.googleapis.com/geo-devrel-public-buckets/newark_nj_1922-661x516.jpeg",imageBounds);historicalOverlay.setMap(map);}declareglobal{interfaceWindow{initMap:()=>void;}}window.initMap=initMap;
// This example uses a GroundOverlay to place an image on the map// showing an antique map of Newark, NJ.lethistoricalOverlay;functioninitMap(){constmap=newgoogle.maps.Map(document.getElementById("map"),{zoom:13,center:{lat:40.74,lng:-74.18},});constimageBounds={north:40.773941,south:40.712216,east:-74.12544,west:-74.22655,};historicalOverlay=newgoogle.maps.GroundOverlay("https://storage.googleapis.com/geo-devrel-public-buckets/newark_nj_1922-661x516.jpeg",imageBounds,);historicalOverlay.setMap(map);}window.initMap=initMap;
Pour retirer une superposition d'une carte, appelez la méthode setMap() de la superposition en transmettant null. Notez que cette méthode ne supprime pas la superposition. Elle la retire simplement de la carte. Si vous souhaitez plutôt supprimer la superposition, vous devez la retirer de la carte, puis définir la superposition elle-même sur null.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/06 (UTC).
[null,null,["Dernière mise à jour le 2025/08/06 (UTC)."],[[["\u003cp\u003eGround overlays let you place images on a map tied to latitude/longitude coordinates.\u003c/p\u003e\n"],["\u003cp\u003eYou can add a ground overlay using the \u003ccode\u003eGroundOverlay\u003c/code\u003e object, specifying the image URL and boundaries.\u003c/p\u003e\n"],["\u003cp\u003eTo remove a ground overlay from the map, call \u003ccode\u003esetMap(null)\u003c/code\u003e on the overlay object.\u003c/p\u003e\n"],["\u003cp\u003eRemoving an overlay from the map doesn't delete it; to delete it, set the overlay object to \u003ccode\u003enull\u003c/code\u003e after removing it from the map.\u003c/p\u003e\n"]]],["Ground overlays, images tied to latitude/longitude coordinates, are added to a map using the `GroundOverlay` constructor, specifying an image URL and `LatLngBounds`. The `setMap()` method then renders the image. Removing an overlay involves calling `setMap(null)` on the overlay object, which detaches it from the map but doesn't delete it. To delete the overlay it needs to be set to null. Example code is provided in TypeScript and JavaScript.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/groundoverlay \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/overlays \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/groundoverlays \"View this page for the JavaScript platform docs.\")\n\n1. [Introduction](#introduction)\n2. [Add a ground overlay](#add)\n3. [Remove a ground overlay](#remove)\n\nIntroduction\n\nOverlays are objects on the map that are tied to\nlatitude/longitude coordinates, so they move when you drag or\nzoom the map. If you want to place an image on a map, you can use a\n`GroundOverlay` object.\n\nFor information on other types of overlay, see\n[Drawing on the map](/maps/documentation/javascript/overlays).\n\nAdd a ground overlay\n\nThe constructor for a\n[`GroundOverlay`](/maps/documentation/javascript/reference#GroundOverlay) specifies a URL of an image\nand the `LatLngBounds` of the image as parameters. The image will\nbe rendered on the map, constrained to the given bounds, and conformed\nusing the map's projection. \n\nTypeScript \n\n```typescript\n// This example uses a GroundOverlay to place an image on the map\n// showing an antique map of Newark, NJ.\n\nlet historicalOverlay;\n\nfunction initMap(): void {\n const map = new google.maps.Map(\n document.getElementById(\"map\") as HTMLElement,\n {\n zoom: 13,\n center: { lat: 40.74, lng: -74.18 },\n }\n );\n\n const imageBounds = {\n north: 40.773941,\n south: 40.712216,\n east: -74.12544,\n west: -74.22655,\n };\n\n historicalOverlay = new google.maps.GroundOverlay(\n \"https://storage.googleapis.com/geo-devrel-public-buckets/newark_nj_1922-661x516.jpeg\",\n imageBounds\n );\n historicalOverlay.setMap(map);\n}\n\ndeclare global {\n interface Window {\n initMap: () =\u003e void;\n }\n}\nwindow.initMap = initMap;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/samples/groundoverlay-simple/index.ts#L8-L41\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\n// This example uses a GroundOverlay to place an image on the map\n// showing an antique map of Newark, NJ.\nlet historicalOverlay;\n\nfunction initMap() {\n const map = new google.maps.Map(document.getElementById(\"map\"), {\n zoom: 13,\n center: { lat: 40.74, lng: -74.18 },\n });\n const imageBounds = {\n north: 40.773941,\n south: 40.712216,\n east: -74.12544,\n west: -74.22655,\n };\n\n historicalOverlay = new google.maps.GroundOverlay(\n \"https://storage.googleapis.com/geo-devrel-public-buckets/newark_nj_1922-661x516.jpeg\",\n imageBounds,\n );\n historicalOverlay.setMap(map);\n}\n\nwindow.initMap = initMap;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/groundoverlay-simple/docs/index.js#L7-L30\n```\n| **Note:** The JavaScript is compiled from the TypeScript snippet.\n[View example](/maps/documentation/javascript/examples/groundoverlay-simple)\n\nTry Sample \n[JSFiddle.net](https://jsfiddle.net/gh/get/library/pure/googlemaps/js-samples/tree/master/dist/samples/groundoverlay-simple/jsfiddle) [Google Cloud Shell](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fgooglemaps%2Fjs-samples&cloudshell_git_branch=sample-groundoverlay-simple&cloudshell_tutorial=cloud_shell_instructions.md&cloudshell_workspace=.)\n\nRemove a ground overlay\n\nTo remove an overlay from a map, call the overlay's\n`setMap()` method, passing `null`. Note that\ncalling this method does not delete the overlay. It removes\nthe overlay from the map. If instead you wish to delete the overlay,\nyou should remove it from the map, and then set the\noverlay itself to `null`. \n\n```javascript\nfunction removeOverlay() {\n historicalOverlay.setMap(null);\n}\n```\n\n[View example](/maps/documentation/javascript/examples/overlay-remove)"]]