Google Maps API를 기반으로 Vue (버전 2.x)를 사용하여 구성 요소를 작성합니다.자바 스크립트에서 결과를 기다리는 함수 만들기
이 API에는 getBounds() (ref)의 경계를 가져 오는 내장 함수가 있습니다. 내 코드에서
, I는 0에 경계 객체와지도가 동일 초기화 :
currentBorders: {
b: {
b: 0,
f: 0,
},
f: {
b: 0,
f: 0,
},
},
그 후, 나는 특정 중심으로지도를 표시하고 나는 현재를 얻기 위해() 함수를 도로 getBounds을 실행 이 중심 된 후지도의 값이 : 이제
getBorders() {
console.log(this.currentBorders); // -> prints the object with all values equal to 0
this.currentBorders = this.$map.getBounds();
console.log(this.currentBorders); // -> prints undefined
return {
llc_lat: this.currentBorders.f.b,
llc_lng: this.currentBorders.b.b,
urc_lat: this.currentBorders.f.f,
urc_lng: this.currentBorders.b.f,
};
},
, 문제는 첫 번째 실행시지도가 아마 때문에, 나는 0으로 설정 currentBorders을 가지고 있지만 도로 getBounds의 첫 번째 실행()가 undefined를 반환한다는 것입니다 아직로드되지 않았습니다.
내가하고 싶은 것은 getBounds가 의미있는 것을 반환 할 때까지 해당 코드의 실행을 차단하는 것입니다. 그게 갈 길이야? 이것을 어떻게 할 수 있습니까?
편집 : 내가 deferredReady을 통해지도를 초기화하는 방법이 있습니다 :
deferredReady() {
this.$map.setOptions({
styles: mapStyles(),
});
this.initializeMapOverlay();
this.canvasContext = this.mapCanvas.getContext("2d");
this.$map.addListener("idle", this.idleHandler);
this.$map.addListener("zoom_changed",() => {
this.resizeCanvas();
this.clearCanvas();
});
this.$map.addListener("mousemove", this.mouseoverHandler);
this.$map.addListener("drag", this.fetchHexagons());
},
지도 인스턴스화와'getBounrds()'호출에 대한 코드를 표시 할 수 있습니까? –
지도가 초기화 될 때까지'getBounds'를 호출하기 만하면 안됩니까? 또는 귀하의 질문입니까? – thanksd