Places UI Kit: A ready-to-use library that provides room for customization and low-code development. Try it out, and share yourinput on your UI Kit experience.

Overlay Map Types

  • This example demonstrates how to overlay a grid of tile coordinates on top of the base map using a customMapType.

  • The overlay showcases the coordinate system of map tiles, with the origin at the northwest corner.

  • The tile coordinates update dynamically as the user pans and zooms the map.

  • The sample provides code in TypeScript, JavaScript, CSS, and HTML to implement the overlay.

This example uses a tile overlayMapType to overlay the map's tilecoordinates on top of the default map tiles.

Read thedocumentation.

TypeScript

/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */classCoordMapTypeimplementsgoogle.maps.MapType{tileSize:google.maps.Size;alt:string|null=null;maxZoom:number=17;minZoom:number=0;name:string|null=null;projection:google.maps.Projection|null=null;radius:number=6378137;constructor(tileSize:google.maps.Size){this.tileSize=tileSize;}getTile(coord:google.maps.Point,zoom:number,ownerDocument:Document):HTMLElement{constdiv=ownerDocument.createElement("div");div.innerHTML=String(coord);div.style.width=this.tileSize.width+"px";div.style.height=this.tileSize.height+"px";div.style.fontSize="10";div.style.borderStyle="solid";div.style.borderWidth="1px";div.style.borderColor="#AAAAAA";returndiv;}releaseTile(tile:Element):void{}}functioninitMap():void{constmap=newgoogle.maps.Map(document.getElementById("map")asHTMLElement,{zoom:10,center:{lat:41.85,lng:-87.65},});// Insert this overlay map type as the first overlay map type at// position 0. Note that all overlay map types appear on top of// their parent base map.constcoordMapType=newCoordMapType(newgoogle.maps.Size(256,256))map.overlayMapTypes.insertAt(0,coordMapType);}declareglobal{interfaceWindow{initMap:()=>void;}}window.initMap=initMap;
Note: Read theguide on using TypeScript and Google Maps.

JavaScript

/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */classCoordMapType{tileSize;alt=null;maxZoom=17;minZoom=0;name=null;projection=null;radius=6378137;constructor(tileSize){this.tileSize=tileSize;}getTile(coord,zoom,ownerDocument){constdiv=ownerDocument.createElement("div");div.innerHTML=String(coord);div.style.width=this.tileSize.width+"px";div.style.height=this.tileSize.height+"px";div.style.fontSize="10";div.style.borderStyle="solid";div.style.borderWidth="1px";div.style.borderColor="#AAAAAA";returndiv;}releaseTile(tile){}}functioninitMap(){constmap=newgoogle.maps.Map(document.getElementById("map"),{zoom:10,center:{lat:41.85,lng:-87.65},});// Insert this overlay map type as the first overlay map type at// position 0. Note that all overlay map types appear on top of// their parent base map.constcoordMapType=newCoordMapType(newgoogle.maps.Size(256,256));map.overlayMapTypes.insertAt(0,coordMapType);}window.initMap=initMap;
Note: The JavaScript is compiled from the TypeScript snippet.

CSS

/* * Always set the map height explicitly to define the size of the div element * that contains the map. */#map{height:100%;}/* * Optional: Makes the sample page fill the window. */html,body{height:100%;margin:0;padding:0;}

HTML

<html>  <head>    <title>Overlay Map Types</title>    <link rel="stylesheet" type="text/css" href="./style.css" />    <script type="module" src="./index.js"></script>  </head>  <body>    <div></div>    <!--       The `defer` attribute causes the script to execute after the full HTML      document has been parsed. For non-blocking uses, avoiding race conditions,      and consistent behavior across browsers, consider loading using Promises. See      https://developers.google.com/maps/documentation/javascript/load-maps-js-api      for more information.      -->    <script      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly"      defer    ></script>  </body></html>

Try Sample

Clone Sample

Git and Node.js are required to run this sample locally. Follow theseinstructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.

gitclone-bsample-maptype-overlayhttps://github.com/googlemaps/js-samples.gitcdjs-samplesnpminpmstart

Other samples can be tried by switching to any branch beginning withsample-SAMPLE_NAME.

gitcheckoutsample-SAMPLE_NAMEnpminpmstart

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

Last updated 2025-12-18 UTC.