Google Maps Platform APIs Implementation and Mapping Solution (Part 5)

Introduction 

Welcome to Part 5 of our deep dive into the realm of the extremely popular Google Maps APIs.  Until now, we have covered more than 50% of the entire Google Maps Platform APIs, and there are just a few more topics to go. Today, we’ll be focusing on a simple web service named Place Photos API

Google Places API 

In the last tutorial, we covered the Place Details API. We learned that it was linked to API requests before that.  However, to get the Place ID to be used in the query, you had to call the Place Search API first. This API request has a similar link.  For instance, in this API, the main required parameter is the Photo Reference ID, which is available inside the ‘photos’ field in the Place Details API. 

This API is used to return any photo of specific height and width using that images’ photo reference. This API would be most useful in parallel with the Place Details API. The major use case would be to display the images you got from the photos field with the Details API.  To complete documentation and exploit all the Place Details API provides, navigate to the URL below: 

https://developers.google.com/maps/documentation/places/web-service/details 

Setup 

They might have made their services public, but these companies certainly aren’t nice enough to give them out for free. To avail of any services from the Google, Maps Platform, follow the instructions here Set up Cloud Console and API Keys. These instructions will help you up your project on the Google Cloud Console and your API keys for usage and billing purposes. 

Place Photos API 

As explained above, this API request is used to return the image of any place by using its ‘photo_reference,’ obtained from the Details API. This request probably has the least number of parameters (3) used to customize your request, among all Google Maps Platform APIs. 

Among the three total parameters included, only one is necessary: the photo reference field, as explained above. The other two optional parameters are ‘maxheight’ and ‘maxwidth’ which are used to restrict the images’ dimensions. We will talk about them further later. 

The Place Photos API is mainly used in the following format: 

https://maps.googleapis.com/maps/api/place/photo/output?parameters 

Place Photos API Required Parameters 

The Photos API only requires one necessary parameter, as stated above, being the Photo Reference field. The below image displays the list of all required and optional parameters of our request. 

Place Photos API Required Parameters 

The ‘photo_reference’ parameter needs to be in String format, and the API will return an error response in case of an invalid photo reference Id. 

Place Photos API Optional Parameters 

The Photos API only has two options, the ‘max-height’ and ‘max-width’. They are used to place constraints on the dimensions, i.e., height and width of the image to be returned. These fields are put in the following format: ‘maxheight’ and ‘maxwidth’. 

For more information regarding this API request’s parameters and other details, go to the official link below: 

https://developers.google.com/maps/documentation/places/web-service/photos 

Format 

https://maps.googleapis.com/maps/api/place/photo?photo_reference=AeJbb3eazFPnJQkZL7MiIA8H-wyf1CTB1fQRJcuY5bQIVnSYTi174WaCscpRugDoqOABkvwwklPevX6KCujaizB3bRXwUzzmQig59DciaLOTrs-NHRX8cGq0c8zvCWWCFfwzni9H17ZEpn4WV8RqRkycCbJGh34QVSPh4Qg6dpe-pmPUUJRA&maxheight=400&maxwidth=400&key=XXXXXXXXXXXXXXXXXXXX 

Response 

The response to this API request is also the simplest amongst the rest of the API services on the Google Maps Platform. Upon calling this API with a valid Photo reference ID, it will simply return the image as it is in response shown below. 

Response 

Conclusion: 

Another day, another Google Maps API thoroughly covered by yours truly.  Each of these API requests have their own use case and can be used to enhance and expand your application in multiple ways. Today’s Photos API might be quite simple and provide only one sort of information; however, it may be especially useful depending on the sort of application you may be developing. The last APIs can be used in various use cases and provide immense benefits to the consumer and developer. 

Learn How to Implement Google Maps APIs

Learn More

Further in this series, we will continue to look at the few remaining Web Service APIs provided in the Google Maps Platform, which are particularly useful in the autocomplete functionality. See you all then! 😉