letmap:google.maps.Map;letcenterCoordinates={lat:42.349134,lng:-71.083184};// Boston, MAletinfoWindow;letcontentString;asyncfunctioninitMap(){const{Map,InfoWindow}=awaitgoogle.maps.importLibrary('maps')asgoogle.maps.MapsLibrary;const{AdvancedMarkerElement}=awaitgoogle.maps.importLibrary('marker')asgoogle.maps.MarkerLibrary;const{Place,Review}=awaitgoogle.maps.importLibrary('places')asgoogle.maps.PlacesLibrary;map=newMap(document.getElementById('map')asHTMLElement,{center:centerCoordinates,zoom:14,// ...});// Use a place ID to create a new Place instance.constplace=newPlace({id:'ChIJpyiwa4Zw44kRBQSGWKv4wgA',// Faneuil Hall Marketplace, Boston, MA});// Call fetchFields, passing 'reviews' and other needed fields.awaitplace.fetchFields({fields:['displayName','formattedAddress','location','reviews'],});// If there are any reviews display the first one.if(place.reviews && place.reviews.length > 0){// Get info for the first review.letreviewRating=place.reviews[0].rating;letreviewText=place.reviews[0].text;letauthorName=place.reviews[0].authorAttribution!.displayName;letauthorUri=place.reviews[0].authorAttribution!.uri;// Format the review using HTML.contentString=` <div id="title"><b>${place.displayName}</b></div> <div id="address">${place.formattedAddress}</div>
<a href="${authorUri}" target="_blank">Author: ${authorName}</a>
<div id="rating">Rating: ${reviewRating} stars</div> <div id="rating"><p>Review: ${reviewText}</p></div>`;}else{contentString='No reviews were found for '+place.displayName+'.';}// Create an infowindow to display the review.infoWindow=newInfoWindow({content:contentString,ariaLabel:place.displayName,});// Add a marker.constmarker=newAdvancedMarkerElement({map,position:place.location,title:place.displayName,});// Show the info window.infoWindow.open({anchor:marker,map,});}initMap();
letmap;letcenterCoordinates={lat:42.349134,lng:-71.083184};// Boston, MAletinfoWindow;letcontentString;asyncfunctioninitMap(){const{Map,InfoWindow}=awaitgoogle.maps.importLibrary("maps");const{AdvancedMarkerElement}=awaitgoogle.maps.importLibrary("marker");const{Place,Review}=awaitgoogle.maps.importLibrary("places");map=newMap(document.getElementById("map"),{center:centerCoordinates,zoom:14,// ...});// Use a place ID to create a new Place instance.constplace=newPlace({id:"ChIJpyiwa4Zw44kRBQSGWKv4wgA",// Faneuil Hall Marketplace, Boston, MA});// Call fetchFields, passing 'reviews' and other needed fields.awaitplace.fetchFields({fields:["displayName","formattedAddress","location","reviews"],});// If there are any reviews display the first one.if(place.reviews && place.reviews.length > 0){// Get info for the first review.letreviewRating=place.reviews[0].rating;letreviewText=place.reviews[0].text;letauthorName=place.reviews[0].authorAttribution.displayName;letauthorUri=place.reviews[0].authorAttribution.uri;// Format the review using HTML.contentString=` <div id="title"><b>${place.displayName}</b></div> <div id="address">${place.formattedAddress}</div>
<a href="${authorUri}" target="_blank">Author: ${authorName}</a>
<div id="rating">Rating: ${reviewRating} stars</div> <div id="rating"><p>Review: ${reviewText}</p></div>`;}else{contentString="No reviews were found for "+place.displayName+".";}// Create an infowindow to display the review.infoWindow=newInfoWindow({content:contentString,ariaLabel:place.displayName,});// Add a marker.constmarker=newAdvancedMarkerElement({map,position:place.location,title:place.displayName,});// Show the info window.infoWindow.open({anchor:marker,map,});}initMap();
/* * 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;}
Git and Node.js are required to run this sample locally. Follow these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.
[null,null,["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eThis example demonstrates how to retrieve place details, including the first review, using the Google Maps JavaScript API.\u003c/p\u003e\n"],["\u003cp\u003eIt displays the retrieved information (place name, address, review, rating, and author) within an info window on the map, anchored to a marker at the place's location.\u003c/p\u003e\n"],["\u003cp\u003eIf no reviews are found, the info window indicates this with a message.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets include TypeScript, JavaScript, CSS, and HTML for implementing this functionality.\u003c/p\u003e\n"],["\u003cp\u003eUsers can interact with the example through a live JSFiddle or by cloning and running the sample code locally.\u003c/p\u003e\n"]]],[],null,["This example retrieves place details including the first place review, and\ndisplays the information in an info window.\n\nRead the [documentation](/maps/documentation/javascript/place-reviews). \n\nTypeScript \n\n```typescript\nlet map: google.maps.Map;\nlet centerCoordinates = { lat: 42.349134, lng: -71.083184 }; // Boston, MA\nlet infoWindow;\nlet contentString;\n\nasync function initMap() {\n const { Map, InfoWindow } = await google.maps.importLibrary('maps') as google.maps.MapsLibrary;\n const { AdvancedMarkerElement } = await google.maps.importLibrary('marker') as google.maps.MarkerLibrary;\n const { Place, Review } = await google.maps.importLibrary('places') as google.maps.PlacesLibrary;\n\n map = new Map(document.getElementById('map') as HTMLElement, {\n center: centerCoordinates,\n zoom: 14,\n // ...\n });\n\n // Use a place ID to create a new Place instance.\n const place = new Place({\n id: 'ChIJpyiwa4Zw44kRBQSGWKv4wgA', // Faneuil Hall Marketplace, Boston, MA\n });\n\n // Call fetchFields, passing 'reviews' and other needed fields.\n await place.fetchFields({\n fields: ['displayName', 'formattedAddress', 'location', 'reviews'],\n });\n\n // If there are any reviews display the first one.\n if (place.reviews && place.reviews.length \u003e 0) {\n // Get info for the first review.\n let reviewRating = place.reviews[0].rating;\n let reviewText = place.reviews[0].text;\n let authorName = place.reviews[0].authorAttribution!.displayName;\n let authorUri = place.reviews[0].authorAttribution!.uri;\n\n // Format the review using HTML.\n contentString =`\n \u003cdiv id=\"title\"\u003e\u003cb\u003e${place.displayName}\u003c/b\u003e\u003c/div\u003e\n \u003cdiv id=\"address\"\u003e${place.formattedAddress}\u003c/div\u003e\n \u003ca href=\"${authorUri}\" target=\"_blank\"\u003eAuthor: ${authorName}\u003c/a\u003e\n \u003cdiv id=\"rating\"\u003eRating: ${reviewRating} stars\u003c/div\u003e\n \u003cdiv id=\"rating\"\u003e\u003cp\u003eReview: ${reviewText}\u003c/p\u003e\u003c/div\u003e`;\n } else {\n contentString = 'No reviews were found for ' + place.displayName + '.';\n }\n\n // Create an infowindow to display the review.\n infoWindow = new InfoWindow({\n content: contentString,\n ariaLabel: place.displayName,\n });\n\n // Add a marker.\n const marker = new AdvancedMarkerElement({\n map,\n position: place.location,\n title: place.displayName,\n });\n\n // Show the info window.\n infoWindow.open({\n anchor: marker,\n map,\n });\n}\n\ninitMap();https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/samples/place-reviews/index.ts#L8-L77\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\nlet map;\nlet centerCoordinates = { lat: 42.349134, lng: -71.083184 }; // Boston, MA\nlet infoWindow;\nlet contentString;\n\nasync function initMap() {\n const { Map, InfoWindow } = await google.maps.importLibrary(\"maps\");\n const { AdvancedMarkerElement } = await google.maps.importLibrary(\"marker\");\n const { Place, Review } = await google.maps.importLibrary(\"places\");\n\n map = new Map(document.getElementById(\"map\"), {\n center: centerCoordinates,\n zoom: 14,\n // ...\n });\n\n // Use a place ID to create a new Place instance.\n const place = new Place({\n id: \"ChIJpyiwa4Zw44kRBQSGWKv4wgA\", // Faneuil Hall Marketplace, Boston, MA\n });\n\n // Call fetchFields, passing 'reviews' and other needed fields.\n await place.fetchFields({\n fields: [\"displayName\", \"formattedAddress\", \"location\", \"reviews\"],\n });\n // If there are any reviews display the first one.\n if (place.reviews && place.reviews.length \u003e 0) {\n // Get info for the first review.\n let reviewRating = place.reviews[0].rating;\n let reviewText = place.reviews[0].text;\n let authorName = place.reviews[0].authorAttribution.displayName;\n let authorUri = place.reviews[0].authorAttribution.uri;\n\n // Format the review using HTML.\n contentString = `\n \u003cdiv id=\"title\"\u003e\u003cb\u003e${place.displayName}\u003c/b\u003e\u003c/div\u003e\n \u003cdiv id=\"address\"\u003e${place.formattedAddress}\u003c/div\u003e\n \u003ca href=\"${authorUri}\" target=\"_blank\"\u003eAuthor: ${authorName}\u003c/a\u003e\n \u003cdiv id=\"rating\"\u003eRating: ${reviewRating} stars\u003c/div\u003e\n \u003cdiv id=\"rating\"\u003e\u003cp\u003eReview: ${reviewText}\u003c/p\u003e\u003c/div\u003e`;\n } else {\n contentString = \"No reviews were found for \" + place.displayName + \".\";\n }\n\n // Create an infowindow to display the review.\n infoWindow = new InfoWindow({\n content: contentString,\n ariaLabel: place.displayName,\n });\n\n // Add a marker.\n const marker = new AdvancedMarkerElement({\n map,\n position: place.location,\n title: place.displayName,\n });\n\n // Show the info window.\n infoWindow.open({\n anchor: marker,\n map,\n });\n}\n\ninitMap();https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/place-reviews/docs/index.js#L7-L75\n```\n| **Note:** The JavaScript is compiled from the TypeScript snippet.\n\nCSS \n\n```css\n/* \n * Always set the map height explicitly to define the size of the div element\n * that contains the map. \n */\n#map {\n height: 100%;\n}\n\n/* \n * Optional: Makes the sample page fill the window. \n */\nhtml,\nbody {\n height: 100%;\n margin: 0;\n padding: 0;\n}\nhttps://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/place-reviews/docs/style.css#L7-L24\n```\n\nHTML \n\n```html\n\u003chtml\u003e\n \u003chead\u003e\n \u003ctitle\u003ePlace Reviews\u003c/title\u003e\n\n \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"./style.css\" /\u003e\n \u003cscript type=\"module\" src=\"./index.js\"\u003e\u003c/script\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"map\"\u003e\u003c/div\u003e\n\n \u003c!-- prettier-ignore --\u003e\n \u003cscript\u003e(g=\u003e{var h,a,k,p=\"The Google Maps JavaScript API\",c=\"google\",l=\"importLibrary\",q=\"__ib__\",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=\u003eh||(h=new Promise(async(f,n)=\u003e{await (a=m.createElement(\"script\"));e.set(\"libraries\",[...r]+\"\");for(k in g)e.set(k.replace(/[A-Z]/g,t=\u003e\"_\"+t[0].toLowerCase()),g[k]);e.set(\"callback\",c+\".maps.\"+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=\u003eh=n(Error(p+\" could not load.\"));a.nonce=m.querySelector(\"script[nonce]\")?.nonce||\"\";m.head.append(a)}));d[l]?console.warn(p+\" only loads once. Ignoring:\",g):d[l]=(f,...n)=\u003er.add(f)&&u().then(()=\u003ed[l](f,...n))})\n ({key: \"AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg\", v: \"weekly\"});\u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003ehttps://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/place-reviews/docs/index.html#L8-L22\n```\n\nTry Sample \n[JSFiddle.net](https://jsfiddle.net/gh/get/library/pure/googlemaps/js-samples/tree/master/dist/samples/place-reviews/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-place-reviews&cloudshell_tutorial=cloud_shell_instructions.md&cloudshell_workspace=.)\n\nClone Sample\n\n\nGit and Node.js are required to run this sample locally. Follow these [instructions](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) to install Node.js and NPM. The following commands clone, install dependencies and start the sample application. \n\n git clone -b sample-place-reviews https://github.com/googlemaps/js-samples.git\n cd js-samples\n npm i\n npm start\n\n\nOther samples can be tried by switching to any branch beginning with `sample-`\u003cvar translate=\"no\"\u003eSAMPLE_NAME\u003c/var\u003e. \n\n git checkout sample-\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nx\"\u003eSAMPLE_NAME\u003c/span\u003e\u003c/var\u003e\n npm i\n npm start"]]