Yer Fotoğrafları (eski)

Avrupa Ekonomik Alanı'ndaki (AEA) geliştiriciler

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

Android için Yerler SDK'sı (Eski), maksimum 1600x1600 piksel boyutunda bir bit eşlem resim döndürür.

Fotoğraf alma işlemi

Bir yerin resmini almak için:

  1. fetchPlace() kullanarak bir Place nesnesi getirmek için Yer Ayrıntıları (Eski) özelliğini kullanın. Yanıt Place nesnesine dahil edilecek alanlar listesine Place.Field PHOTO_METADATAS alanını eklediğinizden emin olun.
  2. FetchPlaceResponse için OnSuccessListener içinde, 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ın genişliği veya yüksekliği en fazla 1.600 piksel olabilir.
  4. Fotoğraf bit eşlemini istemek için PlacesClient.fetchPhoto() kullanın.
  5. OnSuccessListener ekleyin ve fotoğrafı FetchPhotoResponse'dan alın.

Fotoğraf çekme

Aşağıdaki örnekte, bir yer fotoğrafının nasıl alınacağı gösterilmektedir:

Kotlin

// Define a Place ID.
val placeId = PlaceIdProvider.getRandomPlaceId()

// 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 metadata = place.photoMetadatas
        if (metadata == null || metadata.isEmpty()) {
            Log.w(TAG, "No photo metadata.")
            return@addOnSuccessListener
        }
        val photoMetadata = metadata.first()

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

        binding.placePhotosAttributions.text = attributions

        // Create a FetchResolvedPhotoUriRequest.
        val photoRequest = FetchResolvedPhotoUriRequest.builder(photoMetadata)
            .setMaxWidth(500) // Optional.
            .setMaxHeight(300) // Optional.
            .build()
        placesClient.fetchResolvedPhotoUri(photoRequest)
            .addOnSuccessListener { fetchPhotoResponse ->
                val photoUri = fetchPhotoResponse.uri
                Glide.with(this)
                    .load(photoUri)
                    .into(binding.placePhotosResult)
            }.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 = PlaceIdProvider.getRandomPlaceId();

// 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();
                    binding.placePhotosAttributions.setText(attributions);

                    // Create a FetchResolvedPhotoUriRequest.
                    final FetchResolvedPhotoUriRequest photoRequest =
                            FetchResolvedPhotoUriRequest.builder(photoMetadata)
                                    .setMaxWidth(500) // Optional.
                                    .setMaxHeight(300) // Optional.
                                    .build();
                    placesClient
                            .fetchResolvedPhotoUri(photoRequest)
                            .addOnSuccessListener(
                                    (fetchPhotoResponse) -> {
                                        Glide.with(this)
                                                .load(fetchPhotoResponse.getUri())
                                                .into(binding.placePhotosResult);
                                    })
                            .addOnFailureListener(
                                    (exception) -> {
                                        if (exception instanceof ApiException) {
                                            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ıf olmadan kullanılabilir veya gerekli atıf resme dahil edilir. Ancak PhotoMetadata türündeki fotoğraf meta veri nesnesi, iki tür ek atıftan birini içerebilir:

Döndürülen PhotoMetadata nesnesi her iki türden ilişkilendirme içeriyorsa resmi uygulamanızda gösterdiğiniz her yerde ilişkilendirmeyi eklemeniz gerekir. Daha fazla bilgi için Atıfları Gösterme başlıklı makaleyi inceleyin.

Kullanım ve faturalandırma

fetchPhoto() çağrıları için Place Photos (Eski) SKU'su ücretlendirilir. Ayrıntılar için Kullanım ve Faturalandırma sayfasına bakın.