Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get city sights images from Google Places API

I use Google Places Photos Api and I want to get sights images for selected city by placeid or city title.

I try 2 methods:

1. f.e. I send 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

next step is request to

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 contain many objects with placeid, that i use for new request like first

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

response contain photo_reference object which is the 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

result image

It's not the best photo of London...

2. Using textsearch with param query=sights+in+London

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

This request return response which are contains photo_reference objects. finally request is

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

result image

How can i get images like these

like image 639
styopdev Avatar asked Apr 16 '15 08:04

styopdev


2 Answers

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

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

Includes this photo of the Place of Westminster that is also shown on Google Maps.

like image 138
spiv Avatar answered Sep 30 '22 21:09

spiv


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

I'm not familiar with it, but there's already an answer for how to get just images out of your requests to this API: Google custom search for images only

like image 23
miguev Avatar answered Sep 30 '22 21:09

miguev