如何解决带有缩放级别的Google地图的FitBounds
我尝试在Google地图上用两个标记进行划界,这是可行的,如果我搜索的地址与其他地址相距较远,则相机没有问题。但是,当我尝试搜索靠近对方的地址时,相机无法放大中心位置。
我有这两个功能可在拖动标记后进行划界
private getPlaceAutocompleteDelivery(viewChildInput: any,codeCountry: string) {
this.mapsAPILoader.load().then(() => {
const autocomplete = new google.maps.places.Autocomplete(viewChildInput.nativeElement,{
componentRestrictions: { country: codeCountry },types: [this.deliveryAddressType],});
google.maps.event.addListener(autocomplete,'place_changed',() => {
this.universalMarkers.delivery.setMap(null);
const place = autocomplete.getPlace();
this.deliveryAdresse = place;
const coordinates = new google.maps.LatLng(place.geometry.location.lat(),place.geometry.location.lng());
this.universalMarkers.delivery.setPosition(coordinates);
this.universalMarkers.delivery.setMap(this.map);
this.universalMarkers.delivery.setAnimation(google.maps.Animation.DROP);
this.bounds.extend(this.universalMarkers.delivery.getPosition());
this.map.fitBounds(this.bounds);
});
});
}
第二个功能是
private getPlaceAutocompletePickUp(viewChildInput: any,types: [this.pickUpAddressType],() => {
this.universalMarkers.pickUp.setMap(null);
const place = autocomplete.getPlace();
this.pickUpAdresse = place;
const coordinates = new google.maps.LatLng(place.geometry.location.lat(),place.geometry.location.lng());
this.universalMarkers.pickUp.setPosition(coordinates);
this.universalMarkers.pickUp.setMap(this.map);
this.universalMarkers.pickUp.setAnimation(google.maps.Animation.DROP);
this.bounds.extend(this.universalMarkers.pickUp.getPosition());
this.map.fitBounds(this.bounds);
});
});
}
如果我搜索法国南特的地址和法国兰斯的Rue de la Roseraie 44,则结果为
没关系,但如果我在一个地方附近搜索另一个地方,例如75 Av。法国巴黎香榭丽舍大街和法国巴黎福里街44号,结果是
有人可以告诉我如何添加缩放级别以使该拖曳标记居中,并在搜索后得到如下结果:'(
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。