आप अपने ऐप्लिकेशन में दिखाने के लिए किसी जगह की फ़ोटो का अनुरोध करने के लिए Android के लिए Places SDK का इस्तेमाल कर सकते हैं. फ़ोटो सेवा से वापस की जाने वाली फ़ोटो कई तरह के स्रोतों से ली जाती हैं. इनमें कारोबार के मालिक और उपयोगकर्ता के योगदान वाली फ़ोटो शामिल हैं.
फ़ोटो का फ़ॉर्मैट चुनें
Android के लिए Places SDK टूल, अनुरोध की गई फ़ोटो के दो फ़ॉर्मैट के साथ काम करता है:
- Android वर्शन के लिए, सभी जगहें SDK टूल: बिट मैप इमेज दिखाता है. बिट मैप इमेज का साइज़ ज़्यादा से ज़्यादा 1600 x 1600 पिक्सल होता है.
- Android के लिए SDK टूल (नया) वर्शन 3.4 और उसके बाद के वर्शन: बिट मैप इमेज का यूआरआई दिखाता है. बिट मैप इमेज का साइज़ ज़्यादा से ज़्यादा 4800 x 4800 पिक्सल होता है.
फ़ोटो वापस पाने की प्रक्रिया
किसी जगह की इमेज को वापस लाने के लिए:
Place
ऑब्जेक्ट को फ़ेच करने के लिए, जगह की जानकारी का इस्तेमाल करें (fetchPlace()
याfindCurrentPlace()
का इस्तेमाल करें). रिस्पॉन्सPlace
ऑब्जेक्ट में शामिल करने के लिए, फ़ील्ड की सूची मेंPlace.Field PHOTO_METADATAS
फ़ील्ड को ज़रूर शामिल करें.- आपके
FetchPlaceResponse
याFindCurrentPlaceResponse
के लिएOnSuccessListener
में:- रिस्पॉन्स
Place
ऑब्जेक्ट से फ़ोटो का मेटाडेटा ऑब्जेक्ट,PhotoMetadata
टाइप पाने के लिए,Place.getPhotoMetadas()
का इस्तेमाल करें. - बिटमैप इमेज पाने के लिए:
- कोई
FetchPhotoRequest
ऑब्जेक्ट बनाएं. हालांकि, ऑब्जेक्ट की ज़्यादा से ज़्यादा ऊंचाई और चौड़ाई (पिक्सल में) भी तय की जा सकती है. फ़ोटो की चौड़ाई ज़्यादा से ज़्यादा 1600 पिक्सल हो सकती है. - फ़ोटो के बिट मैप का अनुरोध करने के लिए,
PlacesClient.fetchPhoto()
का इस्तेमाल करें. OnSuccessListener
जोड़ें औरFetchPhotoResponse
से फ़ोटो पाएं.
- कोई
- फ़ोटो का यूआरआई पाने के लिए:
- अनुरोध करने के लिए,
FetchResolvedPhotoUriRequest
ऑब्जेक्ट बनाएं. फ़ोटो की चौड़ाई या ऊंचाई 4800 पिक्सल तक हो सकती है. - फ़ोटो यूआरआई का अनुरोध करने के लिए,
PlacesClient.fetchResolvedPhotoUri()
का इस्तेमाल करें. - कोई
OnSuccessListener
जोड़ें औरFetchResolvedPhotoUriResponse
ऑब्जेक्ट से फ़ोटो यूआरआई पाएं.
- अनुरोध करने के लिए,
- रिस्पॉन्स
वर्शन 3.3.0 और इसके बाद के वर्शन में जोड़े गए PhotoMetadata डेटा का ऐक्सेस पाएं
Android के लिए Places SDK टूल (नया) PhotoMetadata
क्लास में AuthorAttributions
फ़ील्ड जोड़ता है. अगर आपके ऐप्लिकेशन में नया SDK टूल चालू है, तो Place.getPhotoMetadas()
से मिले PhotoMetadata
ऑब्जेक्ट में, एक या एक से ज़्यादा लेखक एट्रिब्यूशन शामिल हो सकते हैं.
जब PhotoMetadata
ऑब्जेक्ट में कोई एट्रिब्यूशन होता है, तो आपको वर्शन 3.3.0 में जोड़े गए नए लेखक के एट्रिब्यूशन या 3.2.0 और उससे पहले के वर्शन में उपलब्ध एट्रिब्यूशन में से किसी एक को फ़ोटो के साथ दिखाना होगा. सभी तरह के एट्रिब्यूशन को मैनेज करने के बारे में ज़्यादा जानकारी के लिए, एट्रिब्यूशन देखें.
PhotoMetadata
ऑब्जेक्ट को लेखक के एट्रिब्यूशन से पॉप्युलेट करने के लिए, आपको:
- अपना Google Cloud प्रोजेक्ट सेट अप करते समय, नए SDK टूल को चालू करें.
- किसी गतिविधि या फ़्रैगमेंट में नया SDK टूल शुरू करें.
- जगह की जानकारी के अनुरोध के लिए फ़ील्ड की सूची में
Place.Field.PHOTO_METADATAS
शामिल करें. Place
ऑब्जेक्ट पाने के लिएPlacesClient.fetchPlace()
को कॉल करें औरPhotoMetadata
ऑब्जेक्ट पाने के लिएPlace.getPhotoMetadas()
को कॉल करें. लेखक के एट्रिब्यूशन फ़ील्ड कोPlacesClient.findCurrentPlace()
पर इस्तेमाल नहीं किया जा सकता.- लेखक के एट्रिब्यूशन पाने के लिए,
PhotoMetadata.getAuthorAttributions()
का इस्तेमाल करें.
फ़ोटो लें
यह सेक्शन बताता है कि किसी फ़ोटो को बिटमैप या यूआरआई के तौर पर कैसे वापस पाया जाए.
बिट मैप के तौर पर जगह की फ़ोटो पाएं
नीचे दिए गए उदाहरण में, बिट मैप के तौर पर जगह की फ़ोटो पाने का तरीका बताया गया है.
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. } }); });
जगह की फ़ोटो का यूआरआई पाएं
नीचे दिए गए उदाहरण में, जगह की फ़ोटो का यूआरआई पाने के बारे में बताया गया है.
// 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 FetchResolvedPhotoUriRequest. final FetchResolvedPhotoUriRequest photoRequest = FetchResolvedPhotoUriRequest.builder(photoMetadata) .setMaxWidth(500) // Optional. .setMaxHeight(300) // Optional. .build(); // Request the photo URI placesClient.fetchResolvedPhotoUri(photoRequest).addOnSuccessListener((fetchResolvedPhotoUriResponse) -> { Uri uri = fetchResolvedPhotoUriResponse.getUri(); RequestOptions requestOptions = new RequestOptions().override(Target.SIZE_ORIGINAL); Glide.with(this).load(uri).apply(requestOptions).into(imageView); }).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
के टाइप में, दो तरह के अतिरिक्त एट्रिब्यूशन में से किसी एक को शामिल किया जा सकता है:
- एट्रिब्यूशन, यह एट्रिब्यूशन स्ट्रिंग है जिसे
PhotoMetadata.getAttributions()
ने ऐक्सेस किया है. - AuthorAttributions, एक
AuthorAttributions
ऑब्जेक्ट, जिसेPhotoMetadata.getAuthorAttributions()
ने ऐक्सेस किया है.
अगर दिखाए गए PhotoMetadata
ऑब्जेक्ट में दोनों में से किसी भी तरह का एट्रिब्यूशन शामिल है, तो आपको अपने ऐप्लिकेशन में एट्रिब्यूशन को शामिल करना होगा. जहां भी इमेज दिखाई जा रही है. ज़्यादा जानकारी के लिए,
एट्रिब्यूशन एट्रिब्यूशन देखें.
इस्तेमाल और बिलिंग
fetchPhoto()
पर किए जाने वाले कॉल के लिए, जगह की फ़ोटो SKU का शुल्क लिया जाता है.
ज़्यादा जानकारी के लिए, इस्तेमाल और बिलिंग के पेज पर जाएं.