xkjyeah / vue-google-maps

Google maps component for vue with 2-way data binding
https://xkjyeah.github.io/vue-google-maps/
1.88k stars 474 forks source link

Can not get place detail by placeId #704

Open hoangnkvti opened 4 years ago

hoangnkvti commented 4 years ago

In my selectPlace() function (when click at map), I got lat and lng and placeId. I want to use place detail information, but I can not send a request. How can I do that?

Here is my code:


<GmapMap
              :center=center
              ref="mapRef"
              :zoom="17"
              map-type-id="terrain"
              class="image is-4by3"
              style="width: 100%;"
              @click="selectPlace"
            >
....
selectPlace (map) {
      this.place.latitude = map.latLng.lat()
      this.place.longitude = map.latLng.lng()

      var placeService = new this.google.maps.places.PlacesService(map)
      var request = { placeId: map.placeId }
      placeService.getDetails(request, function (results, status) {
        if (status === 'OK') {
          if (results[0]) {
            alert(results[0].formatted_address)
          } else {
            window.alert('No results found')
          }
        }
      })
    }