我的谷歌地图实现有一个非常奇怪的问题。我从 REST 服务中取回了一个数组,该数组为我提供了 lat/lng,然后我又使用该信息在地图上放置标记并实现功能。
这部分工作正常,当涉及到在页面上输出标记并获取它们的边界并将地图缩放到它们时,我遇到了问题。我已经阅读了几个解决方案,并尝试尽我所能实施它们。
这是我的实现:
// Reset the maps bounds
MapView.bounds = new google.maps.LatLngBounds(null);
// Get the new map bounds
for (var i=0, j=MapView.markers.length; i<j; i++){
var marker = MapView.markers[i],
lat = marker.position.lat(),
lng = marker.position.lng(),
latlng = new google.maps.LatLng(lat, lng);
MapView.bounds.extend(latlng);
};
// Set the map bounds to the new bounds
MapView.map.fitBounds(MapView.bounds);
以下是正在使用的坐标列表:
21.245445,-105.167631
41.887668,-87.622522
49.817492,15.472962
50.075538,14.4378
33.951611,-118.387578
41.887668,-87.622522
14.782827,-90.793702
33.741973,-78.817013
45.922225,-95.408973
28.320306,-81.422964
36.166667,-86.783333
-17.82922,31.053961
-8.708704,115.169616
41.901514,12.460774
-34.013717,23.054811
20.483443,-86.971039
34.933333,34.083333
6.428055,-9.429499
38.79142,-95.960607
43.771033,11.248001
46.271588,13.95641
33.773,-78.779504
40.789342,-3.249749
20.926822,-156.695125
46.271588,13.95641
18.853921,-71.300939
36.462205,-5.011611
25.788969,-80.226439
50.36809,8.73632
37.540667,126.948346
45.495992,-121.5879
14.782827,-90.793701
0,0
13,-76
20.431006,-86.908065
40.75694,-73.984872
64.143935,-21.934099
-17.816667,25.15
12.879721,121.774017
32.640054,-117.084196
-16.522046,28.850942
40.280559,22.50584
39.202686,-106.831683
36.122611,-115.170973
38.79142,-95.960607
18.126285,-65.440099
22.876396,-109.918562
30.36884,-86.324846
36.076518,-115.153343
36.0443,14.251222
41.894809,-87.624214
36.0443,14.251222
-34.035086,23.046469
36.42,25.431667
-17.82922,31.053961
20.696686,-105.292631
18.533333,-68.366667
42.407211,-71.382437
21.158964,-86.845937
9.748917,-83.753428
14.782827,-90.793701
34.852965,32.361479
34.939737,32.461585
34.052234,-118.243685
64.143935,-21.934099
35.369598,24.482727
52.407927,3.222711
47.497912,19.040235
21.158964,-86.845937
37.446719,25.328862
21.160386,-86.843338
39.770247,21.182861
36.124253,-115.168476
46.421684,15.856075
116.468401,39.947856
41.553221,-70.608589
43.706449,7.292265
39.415044,21.737618
21.158964,-86.845937
20.629559,-87.126904
36.832012,25.897065
50.075538,14.4378
8.87509,98.352656
57.702051,11.982304
-24.183889,29.012778
38.904253,-77.047904
0,0
-25.360413,27.09947
55.940209,-3.225319
36.286023,-5.27918
-3.386069,39.971999
20.749045,-105.31098
17.280151,-62.689038
21.040195,-104.358146
14.782827,-90.793702
20.696686,-105.292631
50.071287,14.397221
51.891877,-8.493827
然后我使用这些边界创建一条折线来尝试找出问题所在,奇怪的部分甚至是错误的,但地图甚至没有缩放/平移到这些边界。
折线代码:
var ne = MapView.bounds.getNorthEast();
var sw = MapView.bounds.getSouthWest();
var boundingBoxPoints = [
ne, new google.maps.LatLng(ne.lat(), sw.lng()),
sw, new google.maps.LatLng(sw.lat(), ne.lng()), ne
];
var boundingBox = new google.maps.Polyline({
path: boundingBoxPoints,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
boundingBox.setMap(MapView.map);
结果的图片(这是地图加载时,未更改):
它要么像那样加载(如果我幸运的话),要么加载地图顶部的大部分行程,只有几个显示和大部分地图画布灰色。
我现在完全失去了,有人可以指出我正确的方向吗?