여러 마커가있는 Google지도보기를 만들고 있습니다. 이 마커는 필터 설정이 변경 될 때마다 활성화되는 ajax 요청에 따라 배치됩니다 (예 : 호텔 만 표시)
새 마커가 마커의 경계에 추가 될 때마다 확대 / 축소와 중심을 변경하고 싶습니다. 그러나 어떤 이유로 올바른 방식으로 작동하지 않습니다. 제거 된 마커가 여전히 인식되는 것 같습니다.
누군가 나를 도울 수 있기를 바랍니다 :)
이것은 자바 스크립트 코드입니다.
var locations = [];
$.each( data.result, function( key, item ) {
locations.push([item.Title,item.Latitude,item.Longitude]);
});
console.log(locations);
google.maps.event.trigger(map, 'resize');
//clear marks
for (i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
//set marks
for (i = 0; i < locations.length; i++) {
markers.push( new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
}));
}
//set the center
var bounds = new google.maps.LatLngBounds();
console.log(bounds);
for(i=0;i<markers.length;i++) {
bounds.extend(markers[i].getPosition());
}
map.setCenter(bounds.getCenter());
이것은 5 행의 위치 배열에있는 키 중 하나입니다.
0: "Nationaal Zwemcentrum de Tongelreep"
1: "51.4113463"
2: "5.4760268"
이것은 크래커의 대답과 함께 트릭을 만들었습니다.
http://blog.shamess.info/2009/09/29/zoom-to-fit-all-markers-on-google-maps-api-v3/
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다