[英]Google maps API V3 fitBounds() not working
我想在谷歌地图上调用fitBounds()
,以便用户可以看到自己相对于所选标记/位置的位置。
这是我的函数处理这个:
var fitMapToShowResult = function(index){
var hereLatLng = new google.maps.LatLng (lat,lng); //location of the user defined outside this func
var firstResultLatLng = new google.maps.LatLng(
$scope.searchResults[index].geometry.location.k,
$scope.searchResults[0].geometry.location.B
);
var latlngList = new Array( hereLatLng, firstResultLatLng ); // latlng: an array of instances of GLatLng
var latlngbounds = new google.maps.LatLngBounds();
for (var i=0;i<latlngList.length;i++){
latlngbounds.extend(latlngList[i]);
console.log('latlngbounds',latlngbounds);
}
//$scope.map.setCenter(latlngbounds.getCenter());
$scope.map.fitBounds(latlngbounds);
};
它大约80%的时间都能很好地工作。 但是,标记的大约五分之一完全不在视野范围内,并且变焦太高,以至于两个点无法同时显示。 我究竟做错了什么?
我的地图使用自定义标记可能是相关的。
为了帮助调试,我添加了这段代码来绘制地图上的边界...
rect = new google.maps.Rectangle( {bounds: latlngbounds, map: $scope.map} );
对于前几个结果,它总是看起来很完美:
但往往是不正确的: 请注意,在每个不正确的情况下,看起来矩形的一个尺寸(高度/宽度)是正确的,而另一个则不正确。 我的直觉告诉我这是相关的。
我知道这是一个很受欢迎的问题,但我已经审查了所有其他问题,而且我的问题似乎与其中任何一个都没有重复。 希望这个库存对未来的故障排除者有用,但这些都没有解决我的问题。
谷歌地图V3 fitBounds不准确无用的问题,没有代码,没有答案
Google Maps API v3 - fitBounds只有一个标记用户在没有意识到的情况下重新定义了循环内部。
使用fitBounds()后使用setZoom()与Google Maps API V3和Google Maps API V3 fitbounds()缩小但从未 使用fitBounds和Google Maps不会缩放 fitBounds()异步发生,因此下游操作需要包含在eventListener中。
google maps→fitBounds手动用户将错误的类型参数传递给LatLngBounds
(应该是两个google.maps.LatLng
s)
google maps fitBounds()坏了还是..? & Google maps API V3方法fitBounds()使用错误坐标构建google.maps.LatLngBounds
(而不是将其留空并使用.extend()
)
试图让谷歌地图适合工作超级noob并没有意识到javascript方法区分大小写
谷歌地图V3自定义标记图像和fitBounds() fitBounds()
按预期工作,但用户需要为bug自定义标记提供更多空间
关于可见标记的Google Maps V3 fitBounds关于如何使用fitBounds()
... rtfm的简单问题
谷歌地图API V3 - fitBounds随机工作但偶尔会忽略海洋中的边界和载荷在撰写本文时没有答案。 听起来像无效的lat / lng对。
不要将值用作geometry.location.**k**
,它取决于最小化的文件(使用MinifyJS等工具),然后当谷歌发布新的版本时它会发生变化。
Mr.Upsidown是对的。 我的边界框是错误的,因为我直接引用....geometry.location.k
而不是LatLng
对象。 相应地重构代码纠正了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.