How to get city landmarks images from the Google Places API

I use Google Places Photos Api and I want to get the sights for the selected city by the name of the place or city.

I try 2 methods:

1. fe I am sending a request (used London placeid)

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJdd4hrwug2EcRmSrV3Vo6llI&key=API_KEY 

get location from response

 "lat": 51.5073509 "lng": -0.1277583 

The next step is the request

 https://maps.googleapis.com/maps/api/place/radarsearch/json?location=51.5073509,-0.1277583&radius=5000&types=park|church|cafe|food|bar|night_club|stadium|store&keyword=&key=API_KEY 

response contains many objects with placeid that I use for a new request, for example, the first

 https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJ1eu1vwgIdkgRwjsifpZERQc&key=API_KEY 

the response contains a photo_reference object that is part of my image source

 https://maps.googleapis.com/maps/api/place/photo?photoreference=CoQBcwAAAMLCk4X_WMliqIfISe-mgxRadycuzApodVcaCrTMGP6wQXJaquATedXMkvnjuLAfTG9xzBYQfSNm3iXV07wxHr_X_WDhfjz_yQjmqCYlKwYwK5hH-nl9qi-4ZZqKKtFuphFEY8ka25GYN2sTNMdd0v99j7YCzpR-lHJnl0zA9QoPEhBA5CnCgElBAU7Z92VTShg2GhQUes4fTRKiJlW6rYKYEaNilauWaA&key=API_KEY&maxwidth=1200 

image result

This is not the best photo of London ...

2. Using textearch with the parameter query = attractions + in + London

 https://maps.googleapis.com/maps/api/place/textsearch/json?query=sights+in+London&key=API_KEY 

This request returns a response containing photo_reference objects. finally request

 https://maps.googleapis.com/maps/api/place/photo?photoreference=CnRnAAAAlLsg47UJRPVLdM8_sUbeLSia70EJ_mTisVDfCDTVUYNXl-35BGqzRARtq-Lt1CNcBWy3sKigfBVuF0iCr9-xqp1khK2l5JV3806LKvZrHJCaONYW35UBxxIIwxvxV-df4I4hg6f_zgeeIkWXGSYQhhIQNGYJl0fvHb3HslymbhH1thoUdLhGe8rJVCnyl_y0xAagzkFWs-Y&key=API_KEY&maxwidth=1200 

image result

How can I get images like these

+6
source share
2 answers

The Places API directly returns some photos for cities like London. For example, your London query by location ID:

 https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJdd4hrwug2EcRmSrV3Vo6llI&key=API_KEY 

Includes this Westminster photo , which is also displayed on Google Maps.

+1
source

It looks like you will be looking for an API that displays Google Image search results, and there is one: Google Custom Search https://developers.google.com/custom-search/docs/overview

I am not familiar with this, but there is already an answer to the question of how to get only images from your requests to this API: Google Custom Search for Images

+1
source

Source: https://habr.com/ru/post/985247/


All Articles