Places SDK for Android का इस्तेमाल करके, अपने ऐप्लिकेशन में दिखाने के लिए किसी जगह की फ़ोटो का अनुरोध किया जा सकता है. Photos API से मिली फ़ोटो, कई सोर्स से मिलती हैं. इनमें कारोबार के मालिकों और उपयोगकर्ताओं की ओर से शेयर की गई फ़ोटो शामिल हैं.
Places SDK for Android, ज़्यादा से ज़्यादा 1600 x 1600 पिक्सल वाली बिटमैप इमेज दिखाता है.
फ़ोटो वापस पाने की प्रोसेस
किसी जगह की इमेज वापस पाने के लिए:
Place
ऑब्जेक्ट को फ़ेच करने के लिए, जगह की जानकारी का इस्तेमाल करें. इसके लिए,fetchPlace()
का इस्तेमाल करें. यह पक्का करें कि आपनेPlace.Field PHOTO_METADATAS
फ़ील्ड को उन फ़ील्ड की सूची में शामिल किया हो जिन्हें रिस्पॉन्सPlace
ऑब्जेक्ट में शामिल करना है.- अपने
FetchPlaceResponse
के लिएOnSuccessListener
में,Place
ऑब्जेक्ट सेPhotoMetadata
टाइप का फ़ोटो मेटाडेटा ऑब्जेक्ट पाने के लिए,Place.getPhotoMetadas()
का इस्तेमाल करें. FetchPhotoRequest
ऑब्जेक्ट बनाएं. इसके अलावा, पिक्सल में ज़्यादा से ज़्यादा ऊंचाई और चौड़ाई तय करें. फ़ोटो की चौड़ाई या ऊंचाई ज़्यादा से ज़्यादा 1600 पिक्सल हो सकती है.- फ़ोटो बिटमैप का अनुरोध करने के लिए,
PlacesClient.fetchPhoto()
का इस्तेमाल करें. OnSuccessListener
जोड़ें औरFetchPhotoResponse
से फ़ोटो पाएं.
कोई फ़ोटो पाना
यहां दिए गए उदाहरण में, किसी जगह की फ़ोटो पाने का तरीका बताया गया है:
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. } }); });
एट्रिब्यूशन
ज़्यादातर मामलों में, जगह की फ़ोटो का इस्तेमाल बिना एट्रिब्यूशन के किया जा सकता है. इसके अलावा, कुछ मामलों में इमेज के साथ ज़रूरी एट्रिब्यूशन शामिल होता है. हालांकि, PhotoMetadata
टाइप का फ़ोटो मेटाडेटा ऑब्जेक्ट, दो तरह के अतिरिक्त एट्रिब्यूशन में से किसी एक को शामिल कर सकता है:
- Attributions, यह एक एट्रिब्यूशन स्ट्रिंग है, जिसे
PhotoMetadata.getAttributions()
ऐक्सेस करता है. - AuthorAttributions, एक
AuthorAttributions
ऑब्जेक्ट है, जिसेPhotoMetadata.getAuthorAttributions()
से ऐक्सेस किया जाता है.
अगर जवाब में मिले PhotoMetadata
ऑब्जेक्ट में किसी भी तरह का क्रेडिट शामिल है, तो आपको अपने ऐप्लिकेशन में उस इमेज को दिखाने के लिए, क्रेडिट देना होगा. ज़्यादा जानकारी के लिए,
एट्रिब्यूशन दिखाना लेख पढ़ें.
इस्तेमाल और बिलिंग
fetchPhoto()
पर कॉल करने के लिए, Places Photo SKU का शुल्क लिया जाता है.
ज़्यादा जानकारी के लिए, इस्तेमाल और बिलिंग पेज देखें.