주변 검색 (신규)

플랫폼 선택: Android iOS JavaScript 웹 서비스

주변 검색 (신규) 요청은 검색할 지역을 입력으로 받아들입니다. 은 원으로 지정되며, 원과 반경(미터)입니다. 요청은 일치하는 장소의 목록을 반환하며, 각 목록은 GMSPlace 드림 객체에 대한 검색 결과를 반환할 수 있습니다.

기본적으로 응답에는 검색 영역 내에 모든 유형의 장소가 포함됩니다. 원하는 경우 명시적으로 포함하거나 제외할 장소 유형 목록을 지정하여 응답을 필터링합니다. 있습니다. 예를 들어 응답에 다음 유형의 장소만 포함하도록 지정할 수 있습니다. '음식점', '제과점', '카페'로 분류하거나 '학교' 유형의 모든 장소를 제외하세요.

주변 검색 (신규) 요청

다음을 호출하여 주변 검색 요청 GMSPlacesClient searchNearbyWithRequest:님, 전달 GMSPlaceSearchNearbyRequest 객체는 GMSPlaceSearchNearbyResultCallback, 응답을 처리합니다

GMSPlaceSearchNearbyRequest 객체는 필수선택사항 매개변수를 제공합니다. 필수 매개변수는 다음과 같습니다.

  • GMSPlace 객체에서 반환할 필드의 목록으로, 필드 마스크, 즉 GMSPlaceProperty 필드 목록에 필드를 하나 이상 지정하지 않거나 필드 목록에 없으면 호출이 오류를 반환합니다.
  • 위치 제한: 검색 지역을 정의하는 원입니다.

이 근처 검색 요청 예시는 응답 GMSPlace 객체가 장소 이름 (GMSPlacePropertyName) 및 장소 좌표 포함 검색에 포함된 각 GMSPlace 객체에 대한 (GMSPlacePropertyCoordinate) 있습니다. 또한 응답을 필터링하여 '음식점' 유형의 장소만 반환합니다. '카페'입니다.

Swift

// Array to hold the places in the response
var placeResults: [GMSPlace] = []

// Define the search area as a 500 meter diameter circle in San Francisco, CA.
let circularLocationRestriction = GMSPlaceCircularLocationOption(CLLocationCoordinate2DMake(37.7937, -122.3965), 500)

// Specify the fields to return in the GMSPlace object for each place in the response.
let placeProperties = [GMSPlaceProperty.name, GMSPlaceProperty.coordinate].map {$0.rawValue}

// Create the GMSPlaceSearchNearbyRequest, specifying the search area and GMSPlace fields to return.
var request = GMSPlaceSearchNearbyRequest(locationRestriction: circularLocationRestriction, placeProperties: placeProperties)
let includedTypes = ["restaurant", "cafe"]
request.includedTypes = includedTypes

let callback: GMSPlaceSearchNearbyResultCallback = { [weak self] results, error in
  guard let self, error == nil else {
    if let error {
      print(error.localizedDescription)
    }
    return
  }
  guard let results = results as? [GMSPlace] else {
    return
  }
  placeResults = results
}

GMSPlacesClient.shared().searchNearby(with: request, callback: callback)

Objective-C

// Array to hold the places in the response
_placeResults = [NSArray array];

// Define the search area as a 500 meter diameter circle in San Francisco, CA.
id<GMSPlaceLocationRestriction> circularLocation = GMSPlaceCircularLocationOption(CLLocationCoordinate2DMake(37.7937, -122.3965), 500);

// Create the GMSPlaceSearchNearbyRequest, specifying the search area and GMSPlace fields to return.
GMSPlaceSearchNearbyRequest *request = [[GMSPlaceSearchNearbyRequest alloc]
  initWithLocationRestriction:circularLocation
              placeProperties:@[ GMSPlacePropertyName, GMSPlacePropertyCoordinate ]];

// Set the place types to filter on.
NSArray<NSString *> *includedTypes = @[ @"restaurant", @"cafe" ];
request.includedTypes = [[NSMutableArray alloc] initWithArray:includedTypes];

[_placesClient searchNearbyWithRequest:request
  callback:^(NSArray<GMSPlace *> *_Nullable places, NSError *_Nullable error) {
    if (error != nil) {
      NSLog(@"An error occurred %@", [error localizedDescription]);
      return;
    } else {
        // Get list of places.
        _placeResults = places;
    }
  }
];

GooglePlacesSwift

let restriction = CircularCoordinateRegion(center: CLLocationCoordinate2DMake(37.7937, -122.3965), radius: 500)
let searchNearbyRequest = SearchNearbyRequest(
  locationRestriction: restriction,
  placeProperties: [ .name, .coordinate],
  includedTypes: [ .restaurant, .cafe ],
)
switch await placesClient.searchNearby(with: searchNearbyRequest) {
case .success(let places):
  // Handle places
case .failure(let placesError):
  // Handle error
}

주변 검색 응답

Nearby Search API는 일치하는 항목의 배열을 GMSPlace 드림 객체로서 일치하는 장소당 1개의 GMSPlace 객체가 있습니다.

데이터 필드와 함께 GMSPlace 객체는 응답에는 다음 멤버 함수가 포함되어 있습니다.

  • <ph type="x-smartling-placeholder"></ph> isOpen는 지정된 시간에 장소의 영업 여부를 계산합니다.
  • isOpenAtDate 드림 지정된 날짜에 장소의 개점 여부를 계산합니다.
를 통해 개인정보처리방침을 정의할 수 있습니다.

필수 매개변수

GMSPlaceSearchNearbyRequest 객체를 사용하여 다음에 필요한 매개변수를 지정합니다. 검색

  • 필드 목록

    장소 세부정보를 요청할 때 데이터를 지정해야 합니다. 장소의 GMSPlace 객체에 필드 마스크로 반환됩니다. 포드의 필드 마스크를 사용하려면 GMSPlaceProperty GMSPlaceSearchNearbyRequest 객체에 추가합니다. 필드 마스킹은 불필요한 데이터를 요청하지 않도록 하는 불필요한 처리 시간과 요금 청구를 방지할 수 있습니다.

    다음 필드 중 하나 이상을 지정합니다.

    • 다음 필드는 Nearby Search (Basic) SKU:

      GMSPlacePropertyAddressComponents, GMSPlacePropertyBusinessStatus, GMSPlacePropertyCoordinate, GMSPlacePropertyFormattedAddress, GMSPlacePropertyName, GMSPlacePropertyIconBackgroundColor, GMSPlacePropertyIconImageURL, GMSPlacePropertyPhotos, GMSPlacePropertyPlaceID, GMSPlacePropertyPlusCode, GMSPlacePropertyTypes, GMSPlacePropertyUTCOffsetMinutes, GMSPlacePropertyViewport, GMSPlacePropertyWheelchairAccessibleEntrance

    • 다음 필드는 Nearby Search (Advanced) SKU:

      GMSPlacePropertyCurrentOpeningHours, GMSPlacePropertySecondaryOpeningHours, GMSPlacePropertyPhoneNumber, GMSPlacePropertyPriceLevel, GMSPlacePropertyRating, GMSPlacePropertyOpeningHours, GMSPlacePropertyUserRatingsTotal, GMSPlacePropertyWebsite

    • 다음 필드는 Nearby Search (Preferred) SKU:

      GMSPlacePropertyCurbsidePickup, GMSPlacePropertyDelivery, GMSPlacePropertyDineIn, GMSPlacePropertyEditorialSummary, GMSPlacePropertyReservable, GMSPlacePropertyReviews, GMSPlacePropertyServesBeer, GMSPlacePropertyServesBreakfast, GMSPlacePropertyServesBrunch, GMSPlacePropertyServesDinner, GMSPlacePropertyServesLunch, GMSPlacePropertyServesVegetarianFood, GMSPlacePropertyServesWine, GMSPlacePropertyTakeout

    다음 예는 두 개의 필드 값 를 사용하여 요청에서 반환된 GMSPlace 객체에 nameplaceID 필드:

    Swift

    // Specify the place data types to return.
    let fields: [GMSPlaceProperty] = [.placeID, .name]
            

    Objective-C

    // Specify the place data types to return.
    NSArray<GMSPlaceProperty *> *fields = @[GMSPlacePropertyPlaceID, GMSPlacePropertyName];
            

    GooglePlacesSwift

    // Specify the place data types to return.
    let fields: [PlaceProperty] = [.placeID, .displayName]
            
  • locationRestriction

    GMSPlaceLocationRestriction 원으로 지정되고 중심점으로 정의되는 검색할 영역을 정의하는 객체입니다. 반경(미터) 반경은 0.0 이상, 50000.0 이하여야 합니다. 기본 반경은 0.0입니다. 요청에서 0.0보다 큰 값으로 설정해야 합니다.

선택적 매개변수

GMSPlaceSearchNearbyRequest 객체를 사용하여 다음과 같은 선택적 매개변수를 지정합니다. 검색

  • includeTypes/excludedTypes, includePrimaryTypes/excludedPrimaryTypes

    유형에서 유형 목록을 지정할 수 있음 필터링에 사용되는 표 A 있습니다. 각 유형 제한 카테고리에 최대 50개의 유형을 지정할 수 있습니다.

    한 장소에는 유형에서 단일 기본 유형만 있을 수 있습니다. 다음과 관련된 표 A 있습니다. 예를 들어 기본 유형은 "mexican_restaurant" 또는 "steak_house" 사용 결과를 필터링할 includedPrimaryTypesexcludedPrimaryTypes 장소의 기본 유형입니다.

    또한 장소에는 유형의 여러 유형 값이 있을 수 있습니다. 표 A 관련이 있습니다. 예를 들어 레스토랑의 유형은 다음과 같습니다. "seafood_restaurant", "restaurant", "food" "point_of_interest", "establishment" includedTypes 사용 및 excludedTypes를 사용하여 장소를 가리지 않습니다.

    일반적인 기본 유형(예: "restaurant" 또는 "hotel"인 경우 응답에는 지정합니다. 예를 들어 "restaurant" 그러면 응답에는 "restaurant"이지만 응답에는 더 구체적인 장소가 포함될 수도 있습니다. 기본 유형(예: "chinese_restaurant" 또는 "seafood_restaurant")

    검색이 여러 유형 제한으로 지정된 경우 모든 제한사항을 충족하는 값이 반환됩니다. 예를 들어 {"includedTypes": ["restaurant"], "excludedPrimaryTypes": ["steak_house"]}, 반환된 장소에서는 "restaurant"개의 관련 서비스를 제공하지만 주로 영업하지 않는 경우 "steak_house"로 표현.

    includedTypes

    다음에서 가져온 장소 유형 목록: 검색할 표 A. 이 매개변수를 생략하면 모든 유형의 장소가 반환됩니다.

    excludedTypes

    다음의 장소 유형 목록: 표 A 검색

    includedTypes (예: "school") 및 excludedTypes (예: "primary_school")를 호출하면 "school"(으)로 분류되었지만 다음 카테고리로 분류되지 않은 장소가 포함된 응답 "primary_school"입니다. 응답에는 다음 중 하나 이상의 장소와 일치하는 장소가 포함됩니다. includedTypesexcludedTypes 없음.

    충돌하는 유형이 있는 경우(예: 두 includedTypes에 모두 나타나는 유형) excludedTypes이면 INVALID_REQUEST 오류가 반환됩니다.

    includedPrimaryTypes

    다음의 기본 장소 유형 목록: 포함할 표 A 찾을 수 있습니다.

    excludedPrimaryTypes

    다음의 기본 장소 유형 목록: 제외할 표 A 찾을 수 있습니다.

    충돌하는 기본 유형이 있는 경우(예: includedPrimaryTypesexcludedPrimaryTypes, INVALID_ARGUMENT 오류가 반환됩니다.

  • maxResultCount

    반환할 장소 결과의 최대 개수를 지정합니다. 사이여야 합니다. 1부터 20 (기본값)까지 포함됩니다.

  • rankPreference

    사용할 순위 유형입니다. 이 매개변수를 생략하면 검색 결과의 순위가 인기도에 따라 결정됩니다. 다음 중 하나일 수 있습니다.

    • .popularity (기본값): 인기도에 따라 결과를 정렬합니다.
    • .distance 지정할 수 있습니다.
  • regionCode

    응답 형식을 지정하는 데 사용되는 지역 코드로, <ph type="x-smartling-placeholder"></ph> 2자리 CLDR 코드 값을 제공합니다. 기본값은 없습니다.

    응답의 formattedAddress 필드의 국가 이름이 regionCode인 경우 국가 코드가 formattedAddress에서 생략됩니다. 이 매개변수는 항상 국가를 포함하는 adrFormatAddress에는 영향을 미치지 않습니다. 이름 또는 shortFormattedAddress(포함되지 않음)에 있어야 합니다.

    대부분의 CLDR 코드는 ISO 3166-1 코드 몇 가지 주목할 만한 예외가 있습니다 예를 들어 영국의 ccTLD는 'uk' (.co.uk), ISO 3166-1 코드는 'gb'입니다. (기술적으로 '영국 및 북아일랜드'의 법인 소유입니다. 매개변수는 관련 법률에 따라 결과에 영향을 미칠 수 있습니다.

앱에 특성 표시

앱이 GMSPlacesClient님, 앱은 필수 저작자 표시도 표시해야 합니다.

예를 들어 GMSPlacesClient 객체의 reviews 속성입니다. 최대 다섯 개의 GMSPlaceReview 객체입니다. 각 GMSPlaceReview 객체에는 속성 및 작성자 속성이 포함될 수 있습니다. 앱에서 리뷰를 표시하는 경우 저작자 표시나 작성자도 표시해야 합니다. 저작자 표시입니다.

자세한 내용은 기여 분석이 있습니다.