I want to retrive google place photos from place id in my angular2 application. I'm getting placeId from Autocomplete method.
I'm using angular2-google-map library.
import { Component, NgZone, Inject, OnInit, ViewChild, EventEmitter, ElementRef } from '@angular/core';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AgmCoreModule, MapsAPILoader } from 'angular2-google-maps/core';
declare var google: any;
@Component({
selector: 'add-location-component',
templateUrl: './addLocation.component.html'
})
export class AddLocationComponent implements OnInit {
private googlePlaceId: any;
@ViewChild("search")
public searchElementRef: ElementRef;
public searchControl: FormControl;
constructor(
public authService: AuthService,
private mapsAPILoader: MapsAPILoader,
@Inject(NgZone) private ngZone: NgZone
) { }
ngOnInit() {
this.searchControl = new FormControl();
this.mapsAPILoader.load().then(() => {
let autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement, {
types: ["address"]
});
autocomplete.addListener("place_changed", () => {
this.ngZone.run(() => {
let place = autocomplete.getPlace();
if (place.geometry === undefined || place.geometry === null) {
return;
}
this.googlePlaceId = place.place_id;
console.log(this.googlePlaceId);
});
});
});
}
}
By using place_id or lattitude and longitude I want to fetch first 10 photos of that place. I'm stuck here with angular2-google-map.
Can you guys help me. Thanks.
With this placeId, you'd use the PlacesService class. You call the
getDetails
method and in the callback you receive aPlaceResult
which has aphotos
property (it's an array ofPhotoPlace
on which you call thegetUrl
method to retrieve the displayable picture).(that implies you have retrieved the Place library as well as the core google maps API library)
[edit]
Actually there is much simpler since you use the
Autocomplete
and so you already have aPlaceResult
.