Yerin Fotoğrafları

Platform seçin: Android iOS JavaScript Web Hizmeti

Uygulamanızda görüntülenecek bir yer fotoğrafı isteğinde bulunmak için Android için Yerler SDK'sını kullanabilirsiniz. Fotoğraf hizmeti tarafından döndürülen fotoğraflar, işletme sahipleri ve kullanıcıların katkıda bulunduğu fotoğraflar da dahil olmak üzere çeşitli kaynaklardan gelir.

Android için Yerler SDK'sı, maksimum 1.600x1.600 piksel boyutunda bir bit eşlem resmi döndürür.

Fotoğraf alma işlemi

Bir yer için resim almak üzere:

  1. Bir Place nesnesini getirmek için Yer Ayrıntıları'nı kullanın (fetchPlace() veya findCurrentPlace() kullanın). Place.Field PHOTO_METADATAS alanını, yanıt Place nesnesine dahil edilecek alanlar listesine eklediğinizden emin olun.
  2. FetchPlaceResponse veya FindCurrentPlaceResponse için OnSuccessListener'nda, yanıt Place nesnesinden PhotoMetadata türünde fotoğraf meta veri nesnesini almak için Place.getPhotoMetadas() kullanın.
  3. İsteğe bağlı olarak maksimum yükseklik ve genişliği (piksel cinsinden) belirterek bir FetchPhotoRequest nesnesi oluşturun. Fotoğraflar en fazla 1.600 piksel genişliğe veya yüksekliğe sahip olabilir.
  4. Fotoğraf bit eşlemi istemek için PlacesClient.fetchPhoto() aracını kullanın.
  5. OnSuccessListener ekleyin ve FetchPhotoResponse konumundan fotoğraf alın.

Fotoğraf çekin

Aşağıdaki örnekte bir yer fotoğrafı alma gösterilmektedir:

Kotlin



// Define a Place ID.
val placeId = "INSERT_PLACE_ID_HERE"

// Specify fields. Requests for photos must always have the PHOTO_METADATAS field.
val fields = listOf(Place.Field.PHOTO_METADATAS)

// Get a Place object (this example uses fetchPlace(), but you can also use findCurrentPlace())
val placeRequest = FetchPlaceRequest.newInstance(placeId, fields)

placesClient.fetchPlace(placeRequest)
    .addOnSuccessListener { response: FetchPlaceResponse ->
        val place = response.place

        // Get the photo metadata.
        val metada = place.photoMetadatas
        if (metada == null || metada.isEmpty()) {
            Log.w(TAG, "No photo metadata.")
            return@addOnSuccessListener
        }
        val photoMetadata = metada.first()

        // Get the attribution text.
        val attributions = photoMetadata?.attributions

        // Create a FetchPhotoRequest.
        val photoRequest = FetchPhotoRequest.builder(photoMetadata)
            .setMaxWidth(500) // Optional.
            .setMaxHeight(300) // Optional.
            .build()
        placesClient.fetchPhoto(photoRequest)
            .addOnSuccessListener { fetchPhotoResponse: FetchPhotoResponse ->
                val bitmap = fetchPhotoResponse.bitmap
                imageView.setImageBitmap(bitmap)
            }.addOnFailureListener { exception: Exception ->
                if (exception is ApiException) {
                    Log.e(TAG, "Place not found: " + exception.message)
                    val statusCode = exception.statusCode
                    TODO("Handle error with given status code.")
                }
            }
    }

      

Java


// Define a Place ID.
final String placeId = "INSERT_PLACE_ID_HERE";

// Specify fields. Requests for photos must always have the PHOTO_METADATAS field.
final List<Place.Field> fields = Collections.singletonList(Place.Field.PHOTO_METADATAS);

// Get a Place object (this example uses fetchPlace(), but you can also use findCurrentPlace())
final FetchPlaceRequest placeRequest = FetchPlaceRequest.newInstance(placeId, fields);

placesClient.fetchPlace(placeRequest).addOnSuccessListener((response) -> {
    final Place place = response.getPlace();

    // Get the photo metadata.
    final List<PhotoMetadata> metadata = place.getPhotoMetadatas();
    if (metadata == null || metadata.isEmpty()) {
        Log.w(TAG, "No photo metadata.");
        return;
    }
    final PhotoMetadata photoMetadata = metadata.get(0);

    // Get the attribution text.
    final String attributions = photoMetadata.getAttributions();

    // Create a FetchPhotoRequest.
    final FetchPhotoRequest photoRequest = FetchPhotoRequest.builder(photoMetadata)
        .setMaxWidth(500) // Optional.
        .setMaxHeight(300) // Optional.
        .build();
    placesClient.fetchPhoto(photoRequest).addOnSuccessListener((fetchPhotoResponse) -> {
        Bitmap bitmap = fetchPhotoResponse.getBitmap();
        imageView.setImageBitmap(bitmap);
    }).addOnFailureListener((exception) -> {
        if (exception instanceof ApiException) {
            final ApiException apiException = (ApiException) exception;
            Log.e(TAG, "Place not found: " + exception.getMessage());
            final int statusCode = apiException.getStatusCode();
            // TODO: Handle error with given status code.
        }
    });
});

      

İlişkilendirmeler

Çoğu durumda, yer fotoğrafları atıfta bulunulmadan kullanılabilir veya gerekli atıf resmin parçası olarak dahil edilir. Ancak PhotoMetadata türündeki fotoğraf meta veri nesnesi, iki ek ilişkilendirme türünden birini içerebilir:

Döndürülen PhotoMetadata nesnesi, her iki ilişkilendirme türünü de içeriyorsa görüntüyü görüntülediğiniz her yerde ilişkilendirmeyi uygulamanıza eklemeniz gerekir. Daha fazla bilgi için İlişkilendirmeleri Görüntüleme bölümüne bakın.

Kullanım ve faturalandırma

fetchPhoto() ürününe yapılan aramalar için Yer Fotoğrafı SKU'su ücretlendirilir. Ayrıntılar için Kullanım ve Faturalandırma sayfasını inceleyin.