Google API v3의 지오 코더를 사용하여 국가의지도를 표시하고 있습니다. 국가에 권장 된 뷰포트가 있지만이 뷰포트에 맵을 맞추려면 작동하지 않습니다 (아래 코드에서 fitBounds 함수를 호출하기 전과 후의 경계 참조).Google지도에서 fitbounds()가 경계에 맞지 않습니다.
내가 뭘 잘못하고 있니?
지도의 뷰포트를 results[0].geometry.viewport
으로 어떻게 설정할 수 있습니까? fitBounds()
가능한 최대 줌 레벨을 사용하여지도 캔버스에 맞는 뷰포트에 스냅해야하기 때문에
var geocoder = new google.maps.Geocoder();
geocoder.geocode(
{'address': '{{countrycode}}'},
function(results, status) {
var bounds = new google.maps.LatLngBounds();
bounds = results[0].geometry.viewport;
console.log(bounds); // ((35.173, -12.524), (45.244, 5.098))
console.log(map.getBounds()); // ((34.628, -14.683), (58.283, 27.503))
map.fitBounds(bounds);
console.log(map.getBounds()); // ((25.740, -24.806), (52.442, 17.380))
}
);
Daniel 감사합니다. – jul
나는 이것도하는 방법을 이해하는 데 어려움을 겪었다, 굉장한 상세한 설명! – designermonkey
철저한 설명에 감사드립니다. boundingBox는이를 명확하게하는 데 좋은 아이디어였습니다. – Symmetric