如何从谷歌地图或地点 API 获取地点图片 [英] How to get a picture of a place from google maps or places API

查看:36
本文介绍了如何从谷歌地图或地点 API 获取地点图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Google Places API 检索有关地点的数据,但找不到如何获取该地点的图片,Google Places API 仅提供图标这是不一样的.例如,我需要您在网络浏览器中在 Google 地图中搜索某个地点时获得的照片.Panoramio 通常有更多图片,但 Panoramio 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?

推荐答案

Places API 将为您提供 地点详情回复;然后您可以将坐标发送到 Panoramio API.

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.

例如(取自 API 文档中的示例):

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

https://maps.googleapis.com/maps/api/place/details/json?reference=<位置的大长键>&sensor=true&key=AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI

回复:

{
  "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"
}

我们可以看到坐标是地点" : {纬度":-33.8669710,lng":151.1958750}

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

然后我们可以向 Panoramio 发送请求,插入坐标,并在两侧加上一点摆动空间(我做了 +/- 0.002 度,赤道上的形状为 200 m x 200 m 平方,通常更小).<代码>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

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.

这篇关于如何从谷歌地图或地点 API 获取地点图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆