[英]Get Google Map bounds, given a bounding box, without loading map?
我正在构建商店查找器,并希望实现以下工作流程:
上面的方法很好,但是如果在找到某些商店之前地图实际上并未移动,则最好使用UX。
因此,是否可以按以下方式查询Google Maps: 给定边界框,我们是否可以找到包含特定边界框的正确缩放的Google Map的边界,而无需实际加载Google Map?
我不确定是否可行,因为我猜这取决于页面中map div的宽度。
geocoder.geocode( {'address': search_text }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.panTo(results[0].geometry.location);
map.fitBounds(results[0].geometry.bounds);
var bounds_to_check_for_stores = map.getBounds();
// QUESTION: get bounds_to_check_for_stores without the three preceding steps?
}
}
google.maps.LatLngBounds
api-doc具有一个方法: extend(point:LatLng)
,该方法可让您扩展边界以确保将边界调整为包括作为参数传递的LatLng
点。 的extend
方法返回LatLngBounds
已经调整。
这样,您可以:
Map.getBounds()
。 .geometry.location
属性,调用LatLngBounds.extend
调整边界。 Map.panToBounds
可以更改地图的视口,从而使用户的体验变得简单,因为将仅对视图执行一次更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.