gpt4 book ai didi

javascript - 谷歌地图 API V3 fitBounds() 不工作

转载 作者:搜寻专家 更新时间:2023-11-01 04:36:43 24 4
gpt4 key购买 nike

我想在谷歌地图上调用 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% 的时间里都能完美运行。但大约五分之一的标记完全不在视野范围内,而且缩放比例太高,无法同时看到两个点。我做错了什么?

我的 map 使用自定义标记可能是相关的。

为了协助调试,我添加了这段代码来在 map 上绘制边界...

    rect = new google.maps.Rectangle( {bounds: latlngbounds, map: $scope.map} );

前几个结果看起来总是很完美: enter image description here

但通常它是不正确的: enter image description here enter image description here请注意,在每种不正确的情况下,矩形的一个尺寸(高度/宽度)似乎是正确的,但另一个不正确。我的直觉告诉我这是相关的。

类似问题综述

我知道这是一个很受欢迎的问题,但我已经查看了所有其他问题,我的问题似乎与其中任何一个都不重复。希望这个储备对 future 的故障排除者有用,但这些都没有解决我的问题。

google maps V3 fitBounds not accurate没有代码也没有答案的无用问题

Google Maps API v3 - fitBounds centers only one marker用户在没有意识到的情况下重新定义了循环内部。

Using setZoom() after using fitBounds() with Google Maps API V3 & Google Maps API V3 fitbounds() zooms out but never in & Google Maps with fitBounds don't zoomfitBounds() 异步发生,因此下游操作需要包装在 eventListener 中。

google maps → fitBounds manually用户将不正确的类型参数传递给 LatLngBounds(应该是两个 google.maps.LatLng)

google maps fitBounds() is broken or..? & Google maps API V3 method fitBounds()正在构建带有错误坐标的 google.maps.LatLngBounds(而不是将其留空并使用 .extend())

Trying to get Google Maps fitbounds to work super 菜鸟没有意识到 javascript 方法是区分大小写的

Google maps V3 custom marker images and fitBounds()fitBounds() 按预期工作,但用户需要为错误自定义标记留出更多空间

Google Maps V3 fitBounds on visible markers关于如何使用 fitBounds()... rtfm

的简单问题

Google Maps API V3 - fitBounds randomly works but occasionally ignores bounds and loads in the middle of the ocean在撰写本文时没有答案。听起来像是无效的纬度/经度对。

最佳答案

不要将值用作 geometry.location.**k**,它取决于最小化文件(使用 MinifyJS 等工具),然后当谷歌发布新版本时它会改变.

关于javascript - 谷歌地图 API V3 fitBounds() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26452941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com