Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从google地图或places API获取一个地方的图片_Android_Google Maps_Google Api_Google Places Api_Panoramio - Fatal编程技术网

Android 如何从google地图或places API获取一个地方的图片

Android 如何从google地图或places API获取一个地方的图片,android,google-maps,google-api,google-places-api,panoramio,Android,Google Maps,Google Api,Google Places Api,Panoramio,我正在使用googleplacesapi检索有关地点的数据,但找不到如何获取该地点的图片,googleplacesapi只提供了不同的图标。例如,我需要你在网络浏览器中搜索谷歌地图时得到的照片。Panoramio通常会有更多图片,但Panoramio API只能按位置搜索图片,而不能按特定的餐厅或酒店名称搜索。有什么想法吗?Places API将为您提供地图中的坐标(纬度和经度);然后可以将坐标发送到 例如(摘自API文档中的示例): https://maps.googleapis.com/ma

我正在使用
googleplacesapi
检索有关地点的数据,但找不到如何获取该地点的图片,
googleplacesapi
只提供了不同的图标。例如,我需要你在网络浏览器中搜索谷歌地图时得到的照片。Panoramio通常会有更多图片,但Panoramio API只能按位置搜索图片,而不能按特定的餐厅或酒店名称搜索。有什么想法吗?

Places API将为您提供地图中的坐标(纬度和经度);然后可以将坐标发送到

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

https://maps.googleapis.com/maps/api/place/details/json?reference=&sensor=true&key=AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI

答复:

我们可以看到坐标是 “地点”:{ “lat”:-33.8669710, “液化天然气”:151.1958750 }

然后我们可以向Panoramio发送一个请求,插入坐标,在两边加上一个小的摆动空间(我做了+/-0.002度,赤道处的一个200米x 200米的正方形,通常更小)。
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


您可能需要对响应进行一些过滤以获得最近的照片,但这应该会给您一些帮助。

Places API刚刚在API中添加了直接请求照片的功能:

Places API现在支持返回一张照片(如果适用于一张照片)和最多十张照片(如果适用于一张照片)

如果随请求返回照片数组,则可以使用
maxheight
和/或
maxwidth
传感器
参数将
photo\u引用
从包含的照片对象传递到:

https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CnRvAAAAwMpdHeWlXl-lH0vp7lez4znKPIWSWvgvZFISdKx45AwJVP1Qp37YOrH7sqHMJ8C-vBDC546decipPHchJhHZL94RcTUfPa1jWzo-rSHaTlbNtjh-N68RkcToUCuY9v2HNpo5mziqkir37WU8FJEqVBIQ4k938TI3e7bf8xq-uwDZcxoUbO_ZJzPxremiQurAYzCTwRhE_V0&sensor=false&key=AddYourOwnKeyHere
有关详细信息,请参阅。


<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Places Searchbox</title>
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 50%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #description {
        font-family: Roboto;
        font-size: 15px;
        font-weight: 300;
      }

      #infowindow-content .title {
        font-weight: bold;
      }

      #infowindow-content {
        display: none;
      }

      #map #infowindow-content {
        display: inline;
      }

      .pac-card {
        margin: 10px 10px 0 0;
        border-radius: 2px 0 0 2px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        outline: none;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        background-color: #fff;
        font-family: Roboto;
      }

      #pac-container {
        padding-bottom: 12px;
        margin-right: 12px;
      }

      .pac-controls {
        display: inline-block;
        padding: 5px 11px;
      }

      .pac-controls label {
        font-family: Roboto;
        font-size: 13px;
        font-weight: 300;
      }

      #pac-input {
        background-color: #fff;
        font-family: Roboto;
        font-size: 15px;
        font-weight: 300;
        margin-left: 12px;
        padding: 0 11px 0 13px;
        text-overflow: ellipsis;
        width: 400px;
      }

      #pac-input:focus {
        border-color: #4d90fe;
      }

      #title {
        color: #fff;
        background-color: #4d90fe;
        font-size: 25px;
        font-weight: 500;
        padding: 6px 12px;
      }
      #target {
        width: 345px;
      }
    </style>
  </head>
  <body>
    <input id="pac-input" class="controls" type="text" placeholder="Search Box">
    <div id="map"></div>
    <div id="place-list"></div>
    <script>
      // This example adds a search box to a map, using the Google Place Autocomplete
      // feature. People can enter geographical searches. The search box will return a
      // pick list containing a mix of places and predicted search terms.

      // This example requires the Places library. Include the libraries=places
      // parameter when you first load the API. For example:
      // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">

      function initAutocomplete() {
        var map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: -33.8688, lng: 151.2195},
          zoom: 13,
          mapTypeId: 'roadmap'
        });

        // Create the search box and link it to the UI element.
        var input = document.getElementById('pac-input');
        var searchBox = new google.maps.places.SearchBox(input);
        map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

        // Bias the SearchBox results towards current map's viewport.
        map.addListener('bounds_changed', function() {
          searchBox.setBounds(map.getBounds());
        });

        var markers = [];
        // Listen for the event fired when the user selects a prediction and retrieve
        // more details for that place.
        searchBox.addListener('places_changed', function() {
          var places = searchBox.getPlaces();

          if (places.length == 0) {
            return;
          }

          // Clear out the old markers.
          markers.forEach(function(marker) {
            marker.setMap(null);
          });
          markers = [];

          // For each place, get the icon, name and location.
          var bounds = new google.maps.LatLngBounds();
          places.forEach(function(place) {
            if (!place.geometry) {
              console.log("Returned place contains no geometry");
              return;
            }
            var icon = {
              url: place.icon,
              size: new google.maps.Size(71, 71),
              origin: new google.maps.Point(0, 0),
              anchor: new google.maps.Point(17, 34),
              scaledSize: new google.maps.Size(25, 25)
            };

            var photoUrl = place.photos[0].getUrl({maxWidth: 400, maxHeight: 400});
            var img = document.createElement("img");
            img.setAttribute('src', photoUrl + "photo.jpg");
            document.getElementById('place-list').appendChild(img);

            // Create a marker for each place.
            markers.push(new google.maps.Marker({
              map: map,
              icon: photos[0].getUrl({'maxWidth' : 35,maxHeight' : 35})
              title: place.name,
              position: place.geometry.location
            }));

            if (place.geometry.viewport) {
              // Only geocodes have viewport.
              bounds.union(place.geometry.viewport);
            } else {
              bounds.extend(place.geometry.location);
            }
          });
          map.fitBounds(bounds);
        });
      }

    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=<KEY_API>&libraries=places&callback=initAutocomplete"
         async defer></script>
  </body>
  </html>
放置搜索框 /*始终明确设置贴图高度以定义div的大小 *包含映射的元素*/ #地图{ 身高:50%; } /*可选:使示例页面填充窗口*/ html,正文{ 身高:100%; 保证金:0; 填充:0; } #描述{ 字体系列:Roboto; 字体大小:15px; 字体大小:300; } #infowindowcontent.title{ 字体大小:粗体; } #信息窗口内容{ 显示:无; } #地图#信息窗口内容{ 显示:内联; } .pac卡{ 利润率:10px 10px 0; 边界半径:2px 0 0 2px; 框大小:边框框; -moz框大小:边框框; 大纲:无; 盒影:0 2px 6px rgba(0,0,0,0.3); 背景色:#fff; 字体系列:Roboto; } #pac容器{ 垫底:12px; 右边距:12px; } .pac控制{ 显示:内联块; 填充:5px11px; } .pac控制标签{ 字体系列:Roboto; 字体大小:13px; 字体大小:300; } #pac输入{ 背景色:#fff; 字体系列:Roboto; 字体大小:15px; 字体大小:300; 左边距:12px; 填充:0 11px 0 13px; 文本溢出:省略号; 宽度:400px; } #pac输入:焦点{ 边框颜色:#4d90fe; } #头衔{ 颜色:#fff; 背景色:#4d90fe; 字体大小:25px; 字号:500; 填充:6px 12px; } #目标{ 宽度:345px; } //本例使用Google Place Autocomplete将搜索框添加到地图中 //特色。人们可以进入地理搜索。搜索框将返回一个 //包含位置和预测搜索词组合的拾取列表。 //此示例需要Places库。包括图书馆=地方 //第一次加载API时的参数。例如: // 函数initAutocomplete(){ var map=new google.maps.map(document.getElementById('map'){ 中心:{lat:-33.8688,lng:151.2195}, 缩放:13, mapTypeId:“路线图” }); //创建搜索框并将其链接到UI元素。 var input=document.getElementById('pac-input'); var searchBox=newgoogle.maps.places.searchBox(输入); map.controls[google.maps.ControlPosition.TOP_LEFT].push(输入); //将搜索框结果偏向当前地图的视口。 addListener('bounds_changed',function(){ searchBox.setBounds(map.getBounds()); }); var标记=[]; //侦听用户选择预测并检索时激发的事件 //关于那个地方的更多细节。 searchBox.addListener('places\u changed',function(){ var places=searchBox.getPlaces(); 如果(places.length==0){ 返回; } //清除旧的标记。 markers.forEach(函数(marker){ marker.setMap(空); }); 标记=[]; //对于每个位置,获取图标、名称和位置。 var bounds=new google.maps.LatLngBounds(); 地点。forEach(功能(地点){ 如果(!place.geometry){ log(“返回的位置不包含几何图形”); 返回; } 变量图标={ url:place.icon, 大小:新谷歌地图大小(71,71), 来源:新google.maps.Point(0,0), 主播:新google.maps.Point(17,34), scaledSize:new google.maps.Size(25,25) }; var photoUrl=place.photos
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Places Searchbox</title>
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 50%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #description {
        font-family: Roboto;
        font-size: 15px;
        font-weight: 300;
      }

      #infowindow-content .title {
        font-weight: bold;
      }

      #infowindow-content {
        display: none;
      }

      #map #infowindow-content {
        display: inline;
      }

      .pac-card {
        margin: 10px 10px 0 0;
        border-radius: 2px 0 0 2px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        outline: none;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        background-color: #fff;
        font-family: Roboto;
      }

      #pac-container {
        padding-bottom: 12px;
        margin-right: 12px;
      }

      .pac-controls {
        display: inline-block;
        padding: 5px 11px;
      }

      .pac-controls label {
        font-family: Roboto;
        font-size: 13px;
        font-weight: 300;
      }

      #pac-input {
        background-color: #fff;
        font-family: Roboto;
        font-size: 15px;
        font-weight: 300;
        margin-left: 12px;
        padding: 0 11px 0 13px;
        text-overflow: ellipsis;
        width: 400px;
      }

      #pac-input:focus {
        border-color: #4d90fe;
      }

      #title {
        color: #fff;
        background-color: #4d90fe;
        font-size: 25px;
        font-weight: 500;
        padding: 6px 12px;
      }
      #target {
        width: 345px;
      }
    </style>
  </head>
  <body>
    <input id="pac-input" class="controls" type="text" placeholder="Search Box">
    <div id="map"></div>
    <div id="place-list"></div>
    <script>
      // This example adds a search box to a map, using the Google Place Autocomplete
      // feature. People can enter geographical searches. The search box will return a
      // pick list containing a mix of places and predicted search terms.

      // This example requires the Places library. Include the libraries=places
      // parameter when you first load the API. For example:
      // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">

      function initAutocomplete() {
        var map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: -33.8688, lng: 151.2195},
          zoom: 13,
          mapTypeId: 'roadmap'
        });

        // Create the search box and link it to the UI element.
        var input = document.getElementById('pac-input');
        var searchBox = new google.maps.places.SearchBox(input);
        map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

        // Bias the SearchBox results towards current map's viewport.
        map.addListener('bounds_changed', function() {
          searchBox.setBounds(map.getBounds());
        });

        var markers = [];
        // Listen for the event fired when the user selects a prediction and retrieve
        // more details for that place.
        searchBox.addListener('places_changed', function() {
          var places = searchBox.getPlaces();

          if (places.length == 0) {
            return;
          }

          // Clear out the old markers.
          markers.forEach(function(marker) {
            marker.setMap(null);
          });
          markers = [];

          // For each place, get the icon, name and location.
          var bounds = new google.maps.LatLngBounds();
          places.forEach(function(place) {
            if (!place.geometry) {
              console.log("Returned place contains no geometry");
              return;
            }
            var icon = {
              url: place.icon,
              size: new google.maps.Size(71, 71),
              origin: new google.maps.Point(0, 0),
              anchor: new google.maps.Point(17, 34),
              scaledSize: new google.maps.Size(25, 25)
            };

            var photoUrl = place.photos[0].getUrl({maxWidth: 400, maxHeight: 400});
            var img = document.createElement("img");
            img.setAttribute('src', photoUrl + "photo.jpg");
            document.getElementById('place-list').appendChild(img);

            // Create a marker for each place.
            markers.push(new google.maps.Marker({
              map: map,
              icon: photos[0].getUrl({'maxWidth' : 35,maxHeight' : 35})
              title: place.name,
              position: place.geometry.location
            }));

            if (place.geometry.viewport) {
              // Only geocodes have viewport.
              bounds.union(place.geometry.viewport);
            } else {
              bounds.extend(place.geometry.location);
            }
          });
          map.fitBounds(bounds);
        });
      }

    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=<KEY_API>&libraries=places&callback=initAutocomplete"
         async defer></script>
  </body>
  </html>
 var photoRef;
 if (data.results[i].photos && Array.isArray(data.results[i].photos)) {
 photoRef = data.results[i].photos[0].photo_reference;
 }