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.

Place Search Pagination

  • This example demonstrates a Google Maps integration that displays nearby stores on a map, focusing on a search near Google's Sydney office.

  • A sidebar lists the top 20 search results, with an option to load more results (up to 60) using pagination.

  • Users can click on a listed store in the sidebar to center the map on its location.

  • The sample code utilizes the Google Maps Places Library and is provided in both JavaScript and TypeScript.

This example creates a map that displays the search results for "stores" nearGoogle's office in Sydney, Australia. A sidebar on the right lists the top 20results, and users can click theMore results button to see up to 60results.

Read thedocumentation.

TypeScript

// This example requires the Places library. Include the libraries=places// parameter when you first load the API. For example:// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">functioninitMap():void{// Create the map.constpyrmont={lat:-33.866,lng:151.196};constmap=newgoogle.maps.Map(document.getElementById("map")asHTMLElement,{center:pyrmont,zoom:17,mapId:"8d193001f940fde3",}asgoogle.maps.MapOptions);// Create the places service.constservice=newgoogle.maps.places.PlacesService(map);letgetNextPage:()=>void|false;constmoreButton=document.getElementById("more")asHTMLButtonElement;moreButton.onclick=function(){moreButton.disabled=true;if(getNextPage){getNextPage();}};// Perform a nearby search.service.nearbySearch({location:pyrmont,radius:500,type:"store"},(results:google.maps.places.PlaceResult[]|null,status:google.maps.places.PlacesServiceStatus,pagination:google.maps.places.PlaceSearchPagination|null)=>{if(status!=="OK"||!results)return;addPlaces(results,map);moreButton.disabled=!pagination||!pagination.hasNextPage;if(pagination &&pagination.hasNextPage){getNextPage=()=>{// Note: nextPage will call the same handler function as the initial callpagination.nextPage();};}});}functionaddPlaces(places:google.maps.places.PlaceResult[],map:google.maps.Map){constplacesList=document.getElementById("places")asHTMLElement;for(constplaceofplaces){if(place.geometry &&place.geometry.location){constimage={url:place.icon!,size:newgoogle.maps.Size(71,71),origin:newgoogle.maps.Point(0,0),anchor:newgoogle.maps.Point(17,34),scaledSize:newgoogle.maps.Size(25,25),};newgoogle.maps.Marker({map,icon:image,title:place.name!,position:place.geometry.location,});constli=document.createElement("li");li.textContent=place.name!;placesList.appendChild(li);li.addEventListener("click",()=>{map.setCenter(place.geometry!.location!);});}}}declareglobal{interfaceWindow{initMap:()=>void;}}window.initMap=initMap;
Note: Read theguide on using TypeScript and Google Maps.

JavaScript

// This example requires the Places library. Include the libraries=places// parameter when you first load the API. For example:// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">functioninitMap(){// Create the map.constpyrmont={lat:-33.866,lng:151.196};constmap=newgoogle.maps.Map(document.getElementById("map"),{center:pyrmont,zoom:17,mapId:"8d193001f940fde3",});// Create the places service.constservice=newgoogle.maps.places.PlacesService(map);letgetNextPage;constmoreButton=document.getElementById("more");moreButton.onclick=function(){moreButton.disabled=true;if(getNextPage){getNextPage();}};// Perform a nearby search.service.nearbySearch({location:pyrmont,radius:500,type:"store"},(results,status,pagination)=>{if(status!=="OK"||!results)return;addPlaces(results,map);moreButton.disabled=!pagination||!pagination.hasNextPage;if(pagination &&pagination.hasNextPage){getNextPage=()=>{// Note: nextPage will call the same handler function as the initial callpagination.nextPage();};}},);}functionaddPlaces(places,map){constplacesList=document.getElementById("places");for(constplaceofplaces){if(place.geometry &&place.geometry.location){constimage={url:place.icon,size:newgoogle.maps.Size(71,71),origin:newgoogle.maps.Point(0,0),anchor:newgoogle.maps.Point(17,34),scaledSize:newgoogle.maps.Size(25,25),};newgoogle.maps.Marker({map,icon:image,title:place.name,position:place.geometry.location,});constli=document.createElement("li");li.textContent=place.name;placesList.appendChild(li);li.addEventListener("click",()=>{map.setCenter(place.geometry.location);});}}}window.initMap=initMap;
Note: The JavaScript is compiled from the TypeScript snippet.

CSS

/* Optional: Makes the sample page fill the window. */html,body{height:100%;margin:0;padding:0;}#container{height:100%;display:flex;}#sidebar{flex-basis:5rem;flex-grow:1;padding:1rem;max-width:30rem;height:100%;box-sizing:border-box;overflow:auto;}#map{flex-basis:0;flex-grow:4;height:100%;}#sidebar{display:flex;flex-direction:column;}h2{font-size:1.5rem;margin:005px0;flex-grow:0;}ul{list-style-type:none;padding:0;margin:0;overflow-y:scroll;flex-grow:1;}li{background-color:#f1f1f1;padding:10px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;font-size:1.25rem;cursor:pointer;}li:nth-child(odd){background-color:#fcfcfc;}button{width:100%;padding:1rem;flex-grow:0;cursor:pointer;background:#1a73e8;font-size:1.5rem;color:white;border:none;}button:hover{color:#c5d4f0;}button:disabled{background-color:#9fc1ee;color:#c5d4f0;cursor:auto;}

HTML

<html>  <head>    <title>Place Search Pagination</title>    <link rel="stylesheet" type="text/css" href="./style.css" />    <script type="module" src="./index.js"></script>  </head>  <body>    <div>      <div></div>      <div>        <h2>Results</h2>        <ul></ul>        <button>Load more results</button>      </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&libraries=places&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-place-search-paginationhttps://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-10-31 UTC.