[英]Get Google Map bounds, given a bounding box, without loading map?
I'm building a store finder and would like to implement the following workflow: 我正在构建商店查找器,并希望实现以下工作流程:
The above is fine, but it would be better UX if the map did not actually appear to move until some stores have been found. 上面的方法很好,但是如果在找到某些商店之前地图实际上并未移动,则最好使用UX。
So, is it possible to query Google Maps as follows: Given a bounding box, can we find the the bounds of the correctly zoomed Google Map that contains that particular bounding box, without actually loading the Google Map? 因此,是否可以按以下方式查询Google Maps: 给定边界框,我们是否可以找到包含特定边界框的正确缩放的Google Map的边界,而无需实际加载Google Map?
I'm not sure it's possible, because it depends on the width of the map div in my page, I guess. 我不确定是否可行,因为我猜这取决于页面中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?
}
}
The google.maps.LatLngBounds
api-doc has a method: extend(point:LatLng)
which will allow you to extend a bounds to ensure that the bounds are adjusted to include the LatLng
point passed as a parameter. google.maps.LatLngBounds
api-doc具有一个方法: extend(point:LatLng)
,该方法可让您扩展边界以确保将边界调整为包括作为参数传递的LatLng
点。 The extend
method returns a LatLngBounds
that has been adjusted. 的
extend
方法返回LatLngBounds
已经调整。
With this, you could: 这样,您可以:
Map.getBounds()
. Map.getBounds()
。 LatLngBounds.extend
to adjust the bounds, using the .geometry.location
property of the stores you selected in Step 2. .geometry.location
属性,调用LatLngBounds.extend
调整边界。 Map.panToBounds
to change the map's viewport, keeping the user's experience simple, because only one change to the view will be performed. Map.panToBounds
可以更改地图的视口,从而使用户的体验变得简单,因为将仅对视图执行一次更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.