장소 세부정보 (신규)

플랫폼 선택: Android iOS JavaScript 웹 서비스
유럽 경제 지역 (EEA) 개발자

필드 가져오기

기존 Place 객체 또는 장소 ID가 있는 경우 Place.fetchFields() 메서드를 사용하여 해당 장소에 대한 세부정보를 가져옵니다. 반환할 장소 데이터 필드의 쉼표로 구분된 목록을 제공합니다. 필드 이름을 카멜 표기법으로 지정합니다. 반환된 Place 객체를 사용하여 요청된 필드의 데이터를 가져옵니다.

다음 예에서는 장소 ID를 사용하여 새 Place를 만들고 displayNameformattedAddress 필드를 요청하는 Place.fetchFields()를 호출하고, 지도에 마커를 추가하고, 일부 데이터를 콘솔에 로깅합니다.

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,
    });
}

자바스크립트

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,
    });
}
MapPlace는 이 함수 전에 선언되었습니다.
const { Map } = await google.maps.importLibrary("maps");
const { Place } = await google.maps.importLibrary("places");
전체 예 보기