I implement a google map on the page, where the place identifier is transmitted to me, then I need to get such a place identifier and load a map with this marker. I was looking through the documentation, but it is not clear how I can target the map object from the <agm-map> so that I can set the place identifier. Here is the piece of code:
public latitude: number; public longitude: number; public zoom: number; public placeid: string; constructor( private mapsAPILoader: MapsAPILoader, private ngZone: NgZone ) {} ngOnInit() { //set google maps defaults this.zoom = 4; this.latitude = 39.8282; this.longitude = -98.5795; this.placeid = "ChIJMS2FahDQzRIRcJqX_aUZCAQ"; //set current position this.setCurrentPosition(); this.mapsAPILoader.load().then(() => { //How do i set the agm-map here to load the map with the placeid }); } private setCurrentPosition() { if ("geolocation" in navigator) { navigator.geolocation.getCurrentPosition((position) => { this.latitude = position.coords.latitude; this.longitude = position.coords.longitude; this.zoom = 12; }); } }
Then in the html file I have something like this:
<agm-map [latitude]="latitude" [longitude]="longitude" [scrollwheel]="false" [zoom]="zoom"> <agm-marker [latitude]="latitude" [longitude]="longitude"></agm-marker> </agm-map>
I looked at the GOOGLE documentation and it seems to set the place id, you need something like this
var request = { placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4' }; service = new google.maps.places.PlacesService(map); service.getDetails(request, callback); function callback(place, status) { if (status == google.maps.places.PlacesServiceStatus.OK) { createMarker(place); } }
The problem is that I'm not sure what to pass for map , since I am using <agm-map> .
source share