Stay organized with collections
Save and categorize content based on your preferences.
This example uses a place ID to create a new Place, calls Place.fetchFields
requesting the displayName and formattedAddress fields, adds a marker to the
map, and logs some data to the console.
letmap:google.maps.Map;letcenterCoordinates={lat:37.4161493,lng:-122.0812166};asyncfunctioninitMap(){const{Map}=awaitgoogle.maps.importLibrary("maps")asgoogle.maps.MapsLibrary;map=newMap(document.getElementById('map')asHTMLElement,{center:centerCoordinates,zoom:14,// ...});getPlaceDetails();}asyncfunctiongetPlaceDetails(){const{Place}=awaitgoogle.maps.importLibrary("places")asgoogle.maps.PlacesLibrary;const{AdvancedMarkerElement}=awaitgoogle.maps.importLibrary("marker")asgoogle.maps.MarkerLibrary;// Use place ID to create a new Place instance.constplace=newPlace({id:'ChIJN5Nz71W3j4ARhx5bwpTQEGg',requestedLanguage:'en',// optional});// Call fetchFields, passing the desired data fields.awaitplace.fetchFields({fields:['displayName','formattedAddress','location']});// Log the resultconsole.log(place.displayName);console.log(place.formattedAddress);// Add an Advanced Markerconstmarker=newAdvancedMarkerElement({map,position:place.location,title:place.displayName,});}initMap();
letmap;letcenterCoordinates={lat:37.4161493,lng:-122.0812166};asyncfunctioninitMap(){const{Map}=awaitgoogle.maps.importLibrary("maps");map=newMap(document.getElementById('map'),{center:centerCoordinates,zoom:14,// ...});getPlaceDetails();}asyncfunctiongetPlaceDetails(){const{Place}=awaitgoogle.maps.importLibrary("places");const{AdvancedMarkerElement}=awaitgoogle.maps.importLibrary("marker");// Use place ID to create a new Place instance.constplace=newPlace({id:'ChIJN5Nz71W3j4ARhx5bwpTQEGg',requestedLanguage:'en',// optional});// Call fetchFields, passing the desired data fields.awaitplace.fetchFields({fields:['displayName','formattedAddress','location']});// Log the resultconsole.log(place.displayName);console.log(place.formattedAddress);// Add an Advanced Markerconstmarker=newAdvancedMarkerElement({map,position:place.location,title:place.displayName,});}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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eThis code demonstrates the usage of the Google Maps JavaScript API's Place class to retrieve and display place details.\u003c/p\u003e\n"],["\u003cp\u003eIt fetches the place's display name, formatted address, and location using a place ID.\u003c/p\u003e\n"],["\u003cp\u003eAn advanced marker is added to the map at the place's location, displaying its name.\u003c/p\u003e\n"],["\u003cp\u003eIt utilizes asynchronous functions and the \u003ccode\u003egoogle.maps.importLibrary\u003c/code\u003e method to load necessary libraries.\u003c/p\u003e\n"],["\u003cp\u003eThe sample includes TypeScript and JavaScript code snippets along with HTML and CSS for displaying the map.\u003c/p\u003e\n"]]],[],null,["This example uses a place ID to create a new `Place`, calls `Place.fetchFields`\nrequesting the `displayName` and `formattedAddress` fields, adds a marker to the\nmap, and logs some data to the console.\n\nRead the [documentation](/maps/documentation/javascript/place-details). \n\nTypeScript \n\n```typescript\nlet map: google.maps.Map;\nlet centerCoordinates = { lat: 37.4161493, lng: -122.0812166 };\n\nasync function initMap() {\n const { Map } = await google.maps.importLibrary(\"maps\") as google.maps.MapsLibrary;\n\n map = new Map(document.getElementById('map') as HTMLElement, {\n center: centerCoordinates,\n zoom: 14,\n // ...\n });\n\n getPlaceDetails();\n}\n\nasync function getPlaceDetails() {\n const { Place } = await google.maps.importLibrary(\"places\") as google.maps.PlacesLibrary;\n const { AdvancedMarkerElement } = await google.maps.importLibrary(\"marker\") as google.maps.MarkerLibrary;\n // Use place ID to create a new Place instance.\n const place = new Place({\n id: 'ChIJN5Nz71W3j4ARhx5bwpTQEGg',\n requestedLanguage: 'en', // optional\n });\n\n // Call fetchFields, passing the desired data fields.\n await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location'] });\n\n // Log the result\n console.log(place.displayName);\n console.log(place.formattedAddress);\n\n // Add an Advanced Marker\n const marker = new AdvancedMarkerElement({\n map,\n position: place.location,\n title: place.displayName,\n });\n}\n\ninitMap();https://github.com/googlemaps-samples/js-api-samples/blob/eb299344a468a9a0aa2e81ca28e51bb5395341ee/samples/place-class/index.ts#L8-L51\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: 37.4161493, lng: -122.0812166 };\nasync function initMap() {\n const { Map } = await google.maps.importLibrary(\"maps\");\n map = new Map(document.getElementById('map'), {\n center: centerCoordinates,\n zoom: 14,\n // ...\n });\n getPlaceDetails();\n}\nasync function getPlaceDetails() {\n const { Place } = await google.maps.importLibrary(\"places\");\n const { AdvancedMarkerElement } = await google.maps.importLibrary(\"marker\");\n // Use place ID to create a new Place instance.\n const place = new Place({\n id: 'ChIJN5Nz71W3j4ARhx5bwpTQEGg',\n requestedLanguage: 'en', // optional\n });\n // Call fetchFields, passing the desired data fields.\n await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location'] });\n // Log the result\n console.log(place.displayName);\n console.log(place.formattedAddress);\n // Add an Advanced Marker\n const marker = new AdvancedMarkerElement({\n map,\n position: place.location,\n title: place.displayName,\n });\n}\ninitMap();https://github.com/googlemaps-samples/js-api-samples/blob/eb299344a468a9a0aa2e81ca28e51bb5395341ee/dist/samples/place-class/docs/index.js#L8-L43\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-samples/js-api-samples/blob/eb299344a468a9a0aa2e81ca28e51bb5395341ee/dist/samples/place-class/docs/style.css#L7-L24\n```\n\nHTML \n\n```html\n\u003chtml\u003e\n \u003chead\u003e\n \u003ctitle\u003ePlace Class\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: \"AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8\", v: \"weekly\"});\u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003ehttps://github.com/googlemaps-samples/js-api-samples/blob/eb299344a468a9a0aa2e81ca28e51bb5395341ee/dist/samples/place-class/docs/index.html#L8-L22\n```\n\nTry Sample \n[JSFiddle.net](https://jsfiddle.net/gh/get/library/pure/googlemaps-samples/js-api-samples/tree/main/dist/samples/place-class/jsfiddle)\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 https://github.com/googlemaps-samples/js-api-samples.git\n cd samples/place-class\n npm i\n npm start"]]