Place Details (New)

Select platform: Android iOS JavaScript Web Service
European Economic Area (EEA) developers

Fetch fields

If you have an existing Place object or place ID, use the Place.fetchFields() method to get details about that place. Provide a comma-separated list of place data fields to return; specify field names in camel case. Use the returned Place object to get data for the requested fields.

The following 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.

TypeScript

 async 
  
 function 
  
 getPlaceDetails 
 () 
  
 { 
  
 const 
  
 { 
  
 Place 
  
 } 
  
 = 
  
 await 
  
 google 
 . 
 maps 
 . 
 importLibrary 
 ( 
 "places" 
 ) 
  
 as 
  
 google 
 . 
 maps 
 . 
 PlacesLibrary 
 ; 
  
 const 
  
 { 
  
 AdvancedMarkerElement 
  
 } 
  
 = 
  
 await 
  
 google 
 . 
 maps 
 . 
 importLibrary 
 ( 
 "marker" 
 ) 
  
 as 
  
 google 
 . 
 maps 
 . 
 MarkerLibrary 
 ; 
  
 // Use place ID to create a new Place instance. 
  
 const 
  
 place 
  
 = 
  
 new 
  
 Place 
 ({ 
  
 id 
 : 
  
 'ChIJN5Nz71W3j4ARhx5bwpTQEGg' 
 , 
  
 requestedLanguage 
 : 
  
 'en' 
 , 
  
 // optional 
  
 }); 
  
 // Call fetchFields, passing the desired data fields. 
  
 await 
  
 place 
 . 
 fetchFields 
 ({ 
  
 fields 
 : 
  
 [ 
 'displayName' 
 , 
  
 'formattedAddress' 
 , 
  
 'location' 
 ] 
  
 }); 
  
 // Log the result 
  
 console 
 . 
 log 
 ( 
 place 
 . 
 displayName 
 ); 
  
 console 
 . 
 log 
 ( 
 place 
 . 
 formattedAddress 
 ); 
  
 // Add an Advanced Marker 
  
 const 
  
 marker 
  
 = 
  
 new 
  
 AdvancedMarkerElement 
 ({ 
  
 map 
 , 
  
 position 
 : 
  
 place.location 
 , 
  
 title 
 : 
  
 place.displayName 
 , 
  
 }); 
 } 
  

JavaScript

 async 
  
 function 
  
 getPlaceDetails 
 () 
  
 { 
  
 const 
  
 { 
  
 Place 
  
 } 
  
 = 
  
 await 
  
 google 
 . 
 maps 
 . 
 importLibrary 
 ( 
 "places" 
 ); 
  
 const 
  
 { 
  
 AdvancedMarkerElement 
  
 } 
  
 = 
  
 await 
  
 google 
 . 
 maps 
 . 
 importLibrary 
 ( 
 "marker" 
 ); 
  
 // Use place ID to create a new Place instance. 
  
 const 
  
 place 
  
 = 
  
 new 
  
 Place 
 ({ 
  
 id 
 : 
  
 'ChIJN5Nz71W3j4ARhx5bwpTQEGg' 
 , 
  
 requestedLanguage 
 : 
  
 'en' 
 , 
  
 // optional 
  
 }); 
  
 // Call fetchFields, passing the desired data fields. 
  
 await 
  
 place 
 . 
 fetchFields 
 ({ 
  
 fields 
 : 
  
 [ 
 'displayName' 
 , 
  
 'formattedAddress' 
 , 
  
 'location' 
 ] 
  
 }); 
  
 // Log the result 
  
 console 
 . 
 log 
 ( 
 place 
 . 
 displayName 
 ); 
  
 console 
 . 
 log 
 ( 
 place 
 . 
 formattedAddress 
 ); 
  
 // Add an Advanced Marker 
  
 const 
  
 marker 
  
 = 
  
 new 
  
 AdvancedMarkerElement 
 ({ 
  
 map 
 , 
  
 position 
 : 
  
 place 
 . 
 location 
 , 
  
 title 
 : 
  
 place 
 . 
 displayName 
 , 
  
 }); 
 } 
  
Note that Map and Place have been declared prior to this function:
 const 
  
 { 
  
 Map 
  
 } 
  
 = 
  
 await 
  
 google 
 . 
 maps 
 . 
 importLibrary 
 ( 
 "maps" 
 ); 
 const 
  
 { 
  
 Place 
  
 } 
  
 = 
  
 await 
  
 google 
 . 
 maps 
 . 
 importLibrary 
 ( 
 "places" 
 ); 
See the complete example
Design a Mobile Site
View Site in Mobile | Classic
Share by: