gpt4 book ai didi

jquery - 求 lats/lngs 的平均值(中心)

转载 作者:行者123 更新时间:2023-12-01 06:57:43 25 4
gpt4 key购买 nike

我正在谷歌地图上动态绘制几个点。我正在尝试找到找到给定点的中心的最佳方法。我尝试过使用以下内容:

var mapArray = new Array;
mapArray[0] = new Array(42, 35.391228, -119.008401);
mapArray[1] = new Array(34, 33.874277, -118.131555);
mapArray[2] = new Array(214, 32.6922592, -115.4962203);
mapArray[3] = new Array(216, 33.3818875, -117.2449785);
mapArray[4] = new Array(40, 36.805231, -119.770192);
mapArray[5] = new Array(47, 37.638266, -122.117398);
mapArray[6] = new Array(218, 37.638266, -122.117398);
mapArray[7] = new Array(39, 33.70677, -116.241719);
mapArray[8] = new Array(219, 33.666489, -117.30137);
mapArray[9] = new Array(37, 34.0625743, -118.354077);
mapArray[10] = new Array(217, 34.0625743, -118.354077);
mapArray[11] = new Array(43, 34.195561, -119.179495);
mapArray[12] = new Array(220, 37.671111, -121.873443);
mapArray[13] = new Array(215, 33.736294, -116.405587);
mapArray[14] = new Array(35, 33.978778, -117.383186);
mapArray[15] = new Array(36, 32.8321559, -117.1264585);
mapArray[16] = new Array(46, 37.312298, -121.930904);
mapArray[17] = new Array(221, 1, 1);
mapArray[18] = new Array(41, 33.7453974, -117.8502537);
mapArray[19] = new Array(44, 34.426024, -119.697417);
mapArray[20] = new Array(45, 34.952801, -120.440045);
mapArray[21] = new Array(38, 34.199697, -118.571618);

var avgLat = 0;
var avgLng = 0;
var j = 0;

for (var i in mapArray) {

avgLat = (avgLat + mapArray[i][1]);
avgLng = (avgLng + mapArray[i][2]);

j++;
}

avgLat = avgLat / j;
avgLng = avgLng / j;

map.setCenter(new GLatLng(avgLat, avgLng), 6);

但这并没有给我一个准确的中心。动态绘制 map 中心的最佳方法是什么?

最佳答案

找到纬度和经度的最大值和最小值,然后分别以 (max-min)/2 为中心。

这应该是 (max + min)/2,平均值。

关于jquery - 求 lats/lngs 的平均值(中心),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7235430/

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