새 장소 사진으로 이전
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
장소 사진을 사용하면 고품질 사진 콘텐츠를 웹페이지에 추가할 수 있습니다.
이 페이지에서는 Place
클래스 (신규)와 PlacesService
(기존)의 장소 사진 기능 간 차이점을 설명하고 비교를 위한 코드 스니펫을 제공합니다.
PlacesService
(레거시)은 photos
필드가 요청에 지정된 경우 getDetails()
요청의 PlaceResult
객체 일부로 최대 10개의 PlacePhoto
객체 배열을 반환합니다. textSearch()
및 nearbySearch()
의 경우 가능한 경우 첫 번째 장소 사진이 기본적으로 반환됩니다.
Place
클래스는 요청에 photos
필드가 지정된 경우 fetchFields()
요청의 일부로 최대 10개의 Photo
객체의 배열을 반환합니다.
다음 표에는 Place
클래스와 PlacesService
간의 장소 사진 사용의 주요 차이점이 나와 있습니다.
PlacesService (기존) |
Place (신규) |
PlacePhoto 인터페이스 |
Photo 클래스 |
PlacePhoto 은
html_attributions 을 문자열로 반환합니다. |
Photo 는
AuthorAttribution 인스턴스를 반환합니다. |
메서드에서는 콜백을 사용하여 결과 객체와 google.maps.places.PlacesServiceStatus 응답을 처리해야 합니다. |
Promise를 사용하며 비동기식으로 작동합니다. |
메서드에는 PlacesServiceStatus 확인이 필요합니다. |
필수 상태 확인이 없으며 표준 오류 처리를 사용할 수 있습니다.
자세히 알아보기 |
PlacesService 는 지도 또는 div 요소를 사용하여 인스턴스화해야 합니다. |
Place 는 지도 또는 페이지 요소를 참조하지 않고도 필요한 곳에 인스턴스화할 수 있습니다. |
코드 비교
이 섹션에서는 장소 사진 코드를 비교하여 Places Service와 Place 클래스 간의 차이점을 설명합니다. 코드 스니펫은 각 API에서 장소 사진을 요청하는 데 필요한 코드를 보여줍니다.
장소 서비스 (기존)
다음 스니펫은 PlacesService
를 사용하여 사진을 반환하고 페이지에 첫 번째 사진 결과를 표시하는 방법을 보여줍니다. 이 예에서 장소 세부정보 요청은 name
및 photos
필드와 함께 장소 ID를 지정합니다.
그런 다음 서비스 상태를 확인한 후 첫 번째 사진이 페이지에 표시됩니다.
PlacesService
를 인스턴스화할 때는 지도 또는 div
요소를 지정해야 합니다. 이 예시에는 지도가 없으므로 div
요소가 사용됩니다.
function getPhotos() {
// Construct the Place Details request.
const request = {
placeId: "ChIJydSuSkkUkFQRsqhB-cEtYnw",
fields: ["name", "photos"],
};
// Create an instance of PlacesService.
const attributionDiv = document.getElementById("attribution-div");
const service = new google.maps.places.PlacesService(attributionDiv);
// Check status and display the first photo in an img element.
service.getDetails(request, (place, status) => {
if (
status === google.maps.places.PlacesServiceStatus.OK && place
) {
const photoImg = document.getElementById('image-container');
photoImg.src = place.photos[0].getUrl({maxHeight: 400});
}
});
}
PlacesService
의 작성자 저작자 표시
PlacesService
는 필수 작성자 저작자 표시를 작성자의 Google 프로필 페이지를 가리키는 URL이 포함된 html_attributions
문자열로 반환합니다. 다음 스니펫은 첫 번째 사진 결과의 기여 분석 데이터를 가져오는 방법을 보여줍니다.
let attributionUrl = place.photos[0].html_attributions;
자세히 알아보기
장소 클래스 (신규)
다음 스니펫은 fetchFields()
메서드를 사용하여 표시 이름과 장소 사진을 포함한 장소 세부정보를 반환하는 방법을 보여줍니다.
먼저 장소 ID를 사용하여 새 Place
객체를 인스턴스화한 다음 displayName
및 photos
필드가 지정된 fetchFields()
를 호출합니다.
그러면 1위 사진이 페이지에 표시됩니다. Place
클래스를 사용하는 경우 서비스 상태를 확인할 필요가 없습니다. 자동으로 처리되기 때문입니다.
async function getPhotos() {
// Use a place ID to create a new Place instance.
const place = new google.maps.places.Place({
id: 'ChIJydSuSkkUkFQRsqhB-cEtYnw', // Woodland Park Zoo, Seattle WA
});
// Call fetchFields, passing the needed data fields.
await place.fetchFields({ fields: ['displayName','photos'] });
console.log(place.displayName);
console.log(place.photos[0]);
// Add the first photo to an img element.
const photoImg = document.getElementById('image-container');
photoImg.src = place.photos[0].getURI({maxHeight: 400});
}
Place
클래스의 저작자 표시
Place
클래스는 작성자 이름, 작성자의 Google 프로필 페이지 URI, 작성자의 프로필 사진 URI를 포함하는 AuthorAttribution
인스턴스로 작성자 저작자 표시를 반환합니다. 다음 스니펫은 첫 번째 사진 결과의 기여 분석 데이터를 가져오는 방법을 보여줍니다.
let name = place.photos[0].authorAttributions[0].displayName;
let attributionUrl = place.photos[0].authorAttributions[0].uri;
let photoUrl = place.photos[0].authorAttributions[0].photoUri;
자세히 알아보기
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[],[],null,["# Migrate to the new Place Photos\n\n\u003cbr /\u003e\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\nPlace photos lets you add high quality photographic content to your web pages.\nThis page explains the differences between place photos features in the `Place`\nclass (new) and `PlacesService` (legacy), and provides some code snippets for\ncomparison.\n\n- `PlacesService` (legacy) returns an array of up to 10 [`PlacePhoto`](/maps/documentation/javascript/reference/places-service#PlacePhoto) objects as part of the `PlaceResult` object for any `getDetails()` request if the `photos` field is specified in the request. In the case of `textSearch()` and `nearbySearch()` the first place photo is returned by default if available.\n- The `Place` class returns an array of up to 10 [`Photo`](/maps/documentation/javascript/reference/place#Photo) objects as part of a `fetchFields()` request if the `photos` field is specified in the request.\n\nThe following table lists some of the main differences in the use of place\nphotos between the `Place` class and `PlacesService`:\n\n| [`PlacesService`](/maps/documentation/javascript/reference/places-service) (Legacy) | [`Place`](/maps/documentation/javascript/reference/place) (New) |\n|-----------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|\n| [`PlacePhoto`](/maps/documentation/javascript/reference/places-service#PlacePhoto) interface | [`Photo`](/maps/documentation/javascript/reference/place#Photo) class |\n| `PlacePhoto` returns [`html_attributions`](/maps/documentation/javascript/reference/places-service#PlacePhoto.html_attributions) as a string. | `Photo` returns an [`AuthorAttribution`](/maps/documentation/javascript/reference/place#AuthorAttribution) instance. |\n| Methods require the use of a callback to handle the results object and `google.maps.places.PlacesServiceStatus` response. | Uses Promises, and works asynchronously. |\n| Methods require a `PlacesServiceStatus` check. | No required status check, can use standard error handling. [Learn more](/maps/documentation/javascript/reference/errors). |\n| `PlacesService` must be instantiated using a map or a div element. | `Place` can be instantiated wherever needed, without a reference to a map or page element. |\n\nCode comparison\n---------------\n\nThis section compares code for place photos to illustrate the differences\nbetween the Places Service and the\nPlace class. The code snippets show the code\nrequired to request place photos on each respective API.\n\n### Places service (legacy)\n\nThe following snippet shows returning photos using `PlacesService`, and\ndisplaying the first photo result on the page. In this example, the place\ndetails request specifies a place ID, along with the `name` and `photos` fields.\nThe first photo is then displayed on the page after checking service status.\nWhen instantiating the `PlacesService`, a map or a `div` element must be\nspecified; since this example does not feature a map, a `div` element is used. \n\n function getPhotos() {\n // Construct the Place Details request.\n const request = {\n placeId: \"ChIJydSuSkkUkFQRsqhB-cEtYnw\",\n fields: [\"name\", \"photos\"],\n };\n\n // Create an instance of PlacesService.\n const attributionDiv = document.getElementById(\"attribution-div\");\n const service = new google.maps.places.PlacesService(attributionDiv);\n\n // Check status and display the first photo in an img element.\n service.getDetails(request, (place, status) =\u003e {\n if (\n status === google.maps.places.PlacesServiceStatus.OK && place\n ) {\n const photoImg = document.getElementById('image-container');\n photoImg.src = place.photos[0].getUrl({maxHeight: 400});\n }\n });\n }\n\n#### Author attributions in `PlacesService`\n\nThe `PlacesService` returns the required author attributions as an\n[`html_attributions`](/maps/documentation/javascript/reference/places-service#PlacePhoto.html_attributions)\nstring containing a URL pointing to the author's Google profile page. The\nfollowing snippet shows retrieving attribution data for the first photo result. \n\n let attributionUrl = place.photos[0].html_attributions;\n\n#### Learn more\n\n- [See the documentation](/maps/documentation/javascript/places#places_photos)\n- [`getDetails` reference](/maps/documentation/javascript/reference/places-service#PlacesService.getDetails)\n- [`PlacePhoto` interface reference](/maps/documentation/javascript/reference/places-service#PlacePhoto)\n\n### Place class (new)\n\nThe following snippet shows using the\n[`fetchFields()`](/maps/documentation/javascript/reference/place#Place.fetchFields)\nmethod to return place details including the display name and place photos.\nFirst a new `Place` object is instantiated using a place ID, followed by a call\nto `fetchFields()` where the `displayName` and `photos` fields are specified.\nThe first place photo is then displayed on the page. There is no need to check\nservice status when using the `Place` class, as this is handled automatically. \n\n async function getPhotos() {\n // Use a place ID to create a new Place instance.\n const place = new google.maps.places.Place({\n id: 'ChIJydSuSkkUkFQRsqhB-cEtYnw', // Woodland Park Zoo, Seattle WA\n });\n\n // Call fetchFields, passing the needed data fields.\n await place.fetchFields({ fields: ['displayName','photos'] });\n\n console.log(place.displayName);\n console.log(place.photos[0]);\n // Add the first photo to an img element.\n const photoImg = document.getElementById('image-container');\n photoImg.src = place.photos[0].getURI({maxHeight: 400});\n }\n\n#### Author attributions in the `Place` class\n\nThe `Place` class returns author attributions as an\n[`AuthorAttribution`](/maps/documentation/javascript/reference/place#AuthorAttribution)\ninstance including the author's name, a URI for the author's Google profile\npage, and a URI for the author's profile photo. The following snippet shows\nretrieving attribution data for the first photo result. \n\n let name = place.photos[0].authorAttributions[0].displayName;\n let attributionUrl = place.photos[0].authorAttributions[0].uri;\n let photoUrl = place.photos[0].authorAttributions[0].photoUri;\n\n#### Learn more\n\n- [See the full example](/maps/documentation/javascript/examples/place-photos)\n- [See the documentation](/maps/documentation/javascript/place-photos)\n- [`fetchFields()` reference](/maps/documentation/javascript/reference/place#Place.fetchFields)\n- [`Photo` class reference](/maps/documentation/javascript/reference/place#Photo)"]]