Gli overlay sono oggetti sulla mappa legati alle coordinate di latitudine/longitudine, quindi si spostano quando trascini la mappa o ne aumenti lo zoom. Se vuoi inserire un'immagine su una mappa, puoi utilizzare un oggetto GroundOverlay.
Il costruttore di un
GroundOverlay specifica un URL di un'immagine
e il LatLngBounds dell'immagine come parametri. L'immagine verrà visualizzata sulla mappa, limitata ai limiti specificati e conforme alla proiezione della mappa.
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;
Per rimuovere un overlay da una mappa, chiama il metodo setMap() dell'overlay, passando null. Tieni presente che
la chiamata a questo metodo non elimina l'overlay. Rimuove
l'overlay dalla mappa. Se invece vuoi eliminare l'overlay, deve rimuoverlo dalla mappa e impostare l'overlay stesso su null.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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,[]]