androidgoogle-mapsgoogle-apigoogle-places-apipanoramio

How to get a picture of a place from google maps or places API


I'm using Google Places API to retrieve data about places, but couldn't find how to get a picture of that place, Google Places API just provides icon which is not the same. I need the photo you get when you search for a place in Google Maps in a web browser for example. There is usually more pictures from Panoramio, but Panoramio API can only search for pictures by location and not by a particular restaurant or hotel name for example. Any ideas?


Solution

  • The Places API will give you the coordinates (latitude and longitude) in the place detail response; you can then send the coordinates to the Panoramio API.

    For example (drawing from examples in the API docs):

    https://maps.googleapis.com/maps/api/place/details/json?reference=<big long key for place>&sensor=true&key=AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI

    Response:

    {
      "html_attributions" : [],
      "result" : {
        "address_components" : [
          {
            "long_name" : "48",
            "short_name" : "48",
            "types" : [ "street_number" ]
          },
          {
            "long_name" : "Pirrama Road",
            "short_name" : "Pirrama Road",
            "types" : [ "route" ]
          },
          {
            "long_name" : "Pyrmont",
            "short_name" : "Pyrmont",
            "types" : [ "locality", "political" ]
          },
          {
            "long_name" : "NSW",
            "short_name" : "NSW",
            "types" : [ "administrative_area_level_1", "political" ]
          },
          {
            "long_name" : "AU",
            "short_name" : "AU",
            "types" : [ "country", "political" ]
          },
          {
            "long_name" : "2009",
            "short_name" : "2009",
            "types" : [ "postal_code" ]
          }
        ],
        "formatted_address" : "5/48 Pirrama Road, Pyrmont NSW, Australia",
        "formatted_phone_number" : "(02) 9374 4000",
        "geometry" : {
          "location" : {
            "lat" : -33.8669710,
            "lng" : 151.1958750
          }
        },
        "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
        "id" : "4f89212bf76dde31f092cfc14d7506555d85b5c7",
        "international_phone_number" : "+61 2 9374 4000",
        "name" : "Google Sydney",
        "rating" : 4.60,
        "reference" : "CnRlAAAAAfV6JIqSzL8Cf4VnXn0EaI1d5k3IPhdkEonq0MxiUbQFFSVuptVbXbNH4mrevb0bc7G8yWqTUv76i4KTuO_Wf3OrRHjCJJwzQ0mNLjbYGSVqy2eqyrgOUkl6S_sJfTbHzWZYrfPy7KZaet0mM5S6thIQJYuy5v_JD--ZxXEJLWTQRRoU5UaciXBBo89K-bce18Ii9RsEIws",
        "types" : [ "store", "establishment" ],
        "url" : "http://maps.google.com/maps/place?cid=10281119596374313554",
        "vicinity" : "5/48 Pirrama Road, Pyrmont",
        "website" : "http://www.google.com.au/"
      },
      "status" : "OK"
    }
    

    We can see that the coordinates are "location" : { "lat" : -33.8669710, "lng" : 151.1958750 }

    Then we can send a request to Panoramio, inserting the coordinates, plus a little wiggle room on either side (I did +/- 0.002 degrees, a shape 200 m x 200 m square at the equator, generally smaller). http://www.panoramio.com/map/get_panoramas.php?set=public&from=0&to=20&minx=-33.868&miny=151.193&maxx=-33.864&maxy=151.197&size=medium&mapfilter=true

    You may need to do some filtering of the responses to get the closest photo, but this should give you something to work with.