【发布时间】:2017-11-23 18:25:40
【问题描述】:
我正在一个页面中实现一个谷歌地图,其中一个地点 ID 传递给我,然后我需要获取这样的地点 ID 并使用该标记加载地图。我正在阅读文档,但不清楚如何从<agm-map> 标记定位地图对象,以便我可以设置地点 ID。以下是部分代码:
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;
});
}
}
然后在 html 文件中我有这样的内容:
<agm-map [latitude]="latitude" [longitude]="longitude" [scrollwheel]="false" [zoom]="zoom">
<agm-marker [latitude]="latitude" [longitude]="longitude"></agm-marker>
</agm-map>
我查看了 GOOGLE 文档,它似乎设置了您需要这样的地点 ID
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);
}
}
我的问题是我不确定要为map 传递什么,因为我使用的是<agm-map>。
【问题讨论】:
标签: angular google-maps typescript angular2-google-maps