1
안녕하세요 모두 도움이 필요합니다. Google지도 구성 요소에 여러 마커를 각도 4로 설정하는 데 도움이 필요합니다.이 코드로 표시 할 단일 마커를 얻을 수 있습니다.각도 4 및 Google지도로 여러 마커 설정
ngOnInit() {
const myLatlng = new google.maps.LatLng(40.748817, -73.985428);
const mapOptions = {
zoom: 13,
center: myLatlng,
scrollwheel: false
};
const map = new google.maps.Map(document.getElementById('map'), mapOptions);
const Marker = new google.maps.Marker({
position: myLatlng,
title: 'Hello World!'
});
// To add the marker to the map, call setMap();
Marker.setMap(map);
}
어떻게 수정하여 여러 위치를 표시 할 수 있습니까? 나는 아래와 같은 JSON 위치를 가지고있다.
{
"locations": [
{
"_id": "59eb784fa8e0be0004fb466e",
"updatedAt": "2017-10-21T16:39:43.338Z",
"createdAt": "2017-10-21T16:39:43.338Z",
"latitude": "0.2346285",
"longitude": "32.4352628",
"locationName": "Prime warehouse A",
"locationInfo": "Kampala Warehouse #001",
"__v": 0
},
{
"_id": "1568eb54560be000456466e",
"updatedAt": "2018-10-21T16:39:43.448Z",
"createdAt": "2016-09-11T16:39:43.338Z",
"latitude": "4.3346285",
"longitude": "32.4352628",
"locationName": "Prime warehouse A",
"locationInfo": "Kampala Warehouse #001",
"__v": 0
}
]
}
ngOnit에서 'Error ReferenceError : google is not defined'가 표시되고지도가로드되지 않습니다. –
오케이는 setTimeOut 함수를 사용하여 15 초의 시간 지연을 추가하여 오류를 해결할 수있었습니다. 'ngOnInit() { setTimeout (() => { this.loadMap(); }, 1500); }'나머지 코드를 loadMap 함수로 옮겼습니다. 이제 완벽하게 작동합니다. 도움을 주셔서 감사합니다. @henrisycip –
다행입니다. 제 대답이 도움이 되었다면, 다른 사람들도 그것을 배울 수 있도록 그것을 받아들이십시오. 감사! – henrisycip