【问题标题】:How to get photo place from getPlaceDetails? in VUE如何从 getPlaceDetails 获取照片位置?在 VUE 中
【发布时间】:2019-01-14 14:39:29
【问题描述】:

所以我有一个搜索框,点击“进入”后,我想显示我刚刚选择的地方的照片。 我真的不知道该怎么做,在互联网上进行了一些搜索后,我发现了 getPlaceDetails API。 这是我的 index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>test-jest</title>
    <script type="text/JavaScript" src="https://maps.googleapis.com/maps/api/js?key=MY_KEY&libraries=places"></script>

  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

我的 App.vue:

<template>
  <div id="app">
    <div id="nav">
      <router-link to="/">Home</router-link> |
      <router-link to="/about">About</router-link> |
      <router-link to="/search">Search</router-link>
    </div>
    <router-view/>
  </div>
</template>

最后,超级明星,我的搜索组件:

<template>
  <div id="search-wrapper">
    <div>
    <input id="search-input" ref="vue_google_autocomplete"
        placeholder="Search"
        class="search-location"
        onfocus="value = ''"
        type="text" />
    </div>
  </div>
</template>

<script>
export default {
  mounted() {
    this.autocomplete = new google.maps.places.Autocomplete(
      (this.$refs.vue_google_autocomplete),
      {types: ['geocode'],componentRestrictions: {country: "us"}}
    );
      this.autocomplete.addListener('place_changed', () => {
      let place = this.autocomplete.getPlace();
      let ac = place.address_components;
      let lat = place.geometry.location.lat();
      let lon = place.geometry.location.lng();
      var city = ac[0]["short_name"];
      var country = ac[3]["long_name"];

      console.log(`You're going to ${city}, which is in ${country}`);
      console.log(ac);
    });
  }
  }
</script>

有人可以帮我显示我正在寻找的地方的照片吗?

【问题讨论】:

    标签: vue.js google-places-api photo


    【解决方案1】:

    地点在此 API 中定义为场所、地理位置或著名的景点。大多数道路等不返回图像。

    来源:https://developers.google.com/places/web-service/intro

    检查您的回复是否有photos[] 数组,如果它与上述定义的位置匹配,则照片应该在那里。

    【讨论】:

    • 它没有照片数组。今天,经过一番艰苦的研究,我终于明白了它是如何工作的。
    猜你喜欢
    • 1970-01-01
    • 2013-08-05
    • 2010-10-11
    • 2016-12-21
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多