我目前正在开发一个使用谷歌地图的Angular2项目.
我正试图在该区域周围显示标记和多个标记.
我有地图工作,但似乎无法标记.
<div class="google-maps"></div>
constructor(private _elementRef:ElementRef) {
}
ngAfterViewInit() {
let el = this._elementRef.nativeElement.querySelector('.google-maps');
GoogleMapsLoader.load((google) => {
let myLatlng = new google.maps.LatLng(44.5403,-78.5463);
new google.maps.Map(el, {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
new google.maps.Marker(el,{
draggable: true,
animation: google.maps.Animation.DROP,
position: myLatlng,
title:"Hello World!"
});
});
}
最佳答案 标记功能似乎与官方文档
here不匹配.
let map = new google.maps.Map(el, {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
let marker = new google.maps.Marker({
draggable: true,
animation: google.maps.Animation.DROP,
position: myLatlng,
map: map,//set map created here
title:"Hello World!"
});