我在谷歌地图上有超过120个标记,并希望将2个圆圈绑定到每个标记。 我已经实现了这一点,但我继续收到警告: -
“停止运行此脚本?此页面上的脚本导致您的Web浏览器运行缓慢。如果它继续运行,您的计算机可能会在IE上无响应”。
我仅针对圆形叠加显示此错误。
我该如何解决这个问题?有什么方法可以优化?
以下是示例。地点不是我正在使用的确切位置,但这是我在我的应用程序中实现的方式
<script src="https://maps.googleapis.com/maps/api/js?v=3.4&sensor=false"></script>
<script>
var cityLoacations = [
new google.maps.LatLng(37.782551, -122.445368),
new google.maps.LatLng(37.782745, -122.444586),
new google.maps.LatLng(37.782842, -122.443688),
new google.maps.LatLng(37.782919, -122.442815),
new google.maps.LatLng(37.782992, -122.442112),
new google.maps.LatLng(37.783100, -122.441461),
new google.maps.LatLng(37.783206, -122.440829),
new google.maps.LatLng(37.783273, -122.440324),
new google.maps.LatLng(37.783316, -122.440023),
new google.maps.LatLng(37.783357, -122.439794),
new google.maps.LatLng(37.783371, -122.439687),
new google.maps.LatLng(37.783368, -122.439666),
new google.maps.LatLng(37.783383, -122.439594),
new google.maps.LatLng(37.783508, -122.439525),
new google.maps.LatLng(37.783842, -122.439591),
new google.maps.LatLng(37.784147, -122.439668),
new google.maps.LatLng(37.784206, -122.439686),
new google.maps.LatLng(37.784386, -122.439790),
new google.maps.LatLng(37.784701, -122.439902),
new google.maps.LatLng(37.784965, -122.439938),
new google.maps.LatLng(37.785010, -122.439947),
new google.maps.LatLng(37.785360, -122.439952),
new google.maps.LatLng(37.785715, -122.440030),
new google.maps.LatLng(37.786117, -122.440119),
new google.maps.LatLng(37.786564, -122.440209),
new google.maps.LatLng(37.786905, -122.440270),
new google.maps.LatLng(37.786956, -122.440279),
new google.maps.LatLng(37.800224, -122.433520),
new google.maps.LatLng(37.800155, -122.434101),
new google.maps.LatLng(37.800160, -122.434430),
new google.maps.LatLng(37.800378, -122.434527),
new google.maps.LatLng(37.800738, -122.434598),
new google.maps.LatLng(37.800938, -122.434650),
new google.maps.LatLng(37.801024, -122.434889),
new google.maps.LatLng(37.800955, -122.435392),
new google.maps.LatLng(37.800886, -122.435959),
new google.maps.LatLng(37.800811, -122.436275),
new google.maps.LatLng(37.800788, -122.436299),
new google.maps.LatLng(37.800719, -122.436302),
new google.maps.LatLng(37.800702, -122.436298),
new google.maps.LatLng(37.800661, -122.436273),
new google.maps.LatLng(37.800395, -122.436172),
new google.maps.LatLng(37.800228, -122.436116),
new google.maps.LatLng(37.800169, -122.436130),
new google.maps.LatLng(37.800066, -122.436167),
new google.maps.LatLng(37.784345, -122.422922),
new google.maps.LatLng(37.784389, -122.422926),
new google.maps.LatLng(37.784437, -122.422924),
new google.maps.LatLng(37.784746, -122.422818),
new google.maps.LatLng(37.785436, -122.422959),
new google.maps.LatLng(37.786120, -122.423112),
new google.maps.LatLng(37.786433, -122.423029),
new google.maps.LatLng(37.786631, -122.421213),
new google.maps.LatLng(37.786660, -122.421033),
new google.maps.LatLng(37.786801, -122.420141),
new google.maps.LatLng(37.786823, -122.420034),
new google.maps.LatLng(37.786831, -122.419916),
new google.maps.LatLng(37.787034, -122.418208),
new google.maps.LatLng(37.787056, -122.418034),
new google.maps.LatLng(37.787169, -122.417145),
new google.maps.LatLng(37.787217, -122.416715),
new google.maps.LatLng(37.786144, -122.416403),
new google.maps.LatLng(37.785292, -122.416257),
new google.maps.LatLng(37.780666, -122.390374),
new google.maps.LatLng(37.780501, -122.391281),
new google.maps.LatLng(37.780148, -122.392052),
new google.maps.LatLng(37.780173, -122.391148),
new google.maps.LatLng(37.780693, -122.390592),
new google.maps.LatLng(37.781261, -122.391142),
new google.maps.LatLng(37.781808, -122.391730),
new google.maps.LatLng(37.782340, -122.392341),
new google.maps.LatLng(37.782812, -122.393022),
new google.maps.LatLng(37.783300, -122.393672),
new google.maps.LatLng(37.783809, -122.394275),
new google.maps.LatLng(37.784246, -122.394979),
new google.maps.LatLng(37.784791, -122.395958),
new google.maps.LatLng(37.785675, -122.396746),
new google.maps.LatLng(37.786262, -122.395780),
new google.maps.LatLng(37.786776, -122.395093),
new google.maps.LatLng(37.787282, -122.394426),
new google.maps.LatLng(37.787783, -122.393767),
new google.maps.LatLng(37.788343, -122.393184),
new google.maps.LatLng(37.788895, -122.392506),
new google.maps.LatLng(37.789371, -122.391701),
new google.maps.LatLng(37.789722, -122.390952),
new google.maps.LatLng(37.790315, -122.390305),
new google.maps.LatLng(37.790738, -122.389616),
new google.maps.LatLng(37.779448, -122.438702),
new google.maps.LatLng(37.779023, -122.438585),
new google.maps.LatLng(37.778542, -122.438492),
new google.maps.LatLng(37.778100, -122.438411),
new google.maps.LatLng(37.777986, -122.438376),
new google.maps.LatLng(37.777680, -122.438313),
new google.maps.LatLng(37.777316, -122.438273),
new google.maps.LatLng(37.777135, -122.438254),
new google.maps.LatLng(37.776987, -122.438303),
new google.maps.LatLng(37.776946, -122.438404),
new google.maps.LatLng(37.776944, -122.438467),
new google.maps.LatLng(37.776892, -122.438459),
new google.maps.LatLng(37.776842, -122.438442),
new google.maps.LatLng(37.776822, -122.438391),
new google.maps.LatLng(37.776814, -122.438412),
new google.maps.LatLng(37.776787, -122.438628),
new google.maps.LatLng(37.776729, -122.438650),
new google.maps.LatLng(37.776759, -122.438677),
new google.maps.LatLng(37.776772, -122.438498),
new google.maps.LatLng(37.776787, -122.438389),
new google.maps.LatLng(37.776848, -122.438283),
new google.maps.LatLng(37.776870, -122.438239),
new google.maps.LatLng(37.777015, -122.438198),
new google.maps.LatLng(37.777333, -122.438256),
new google.maps.LatLng(37.777595, -122.438308),
new google.maps.LatLng(37.777797, -122.438344),
new google.maps.LatLng(37.778160, -122.438442),
new google.maps.LatLng(37.778414, -122.438508),
new google.maps.LatLng(37.778445, -122.438516),
new google.maps.LatLng(37.778503, -122.438529),
new google.maps.LatLng(37.778607, -122.438549),
new google.maps.LatLng(37.778670, -122.438644),
new google.maps.LatLng(37.778847, -122.438706),
new google.maps.LatLng(37.779240, -122.438744)
];
var cityOuterCircle , cityInnerCircle;
function addMarkers() {
for (var city in cityLoacations) {
var myLatlng = new google.maps.LatLng(city[0],city[1]);
var marker = new google.maps.Marker({
position: myLatlng
});
marker.setMap(map);
}
}
function addCircle() {
for (var city in cityLoacations) {
var outerCircleOptions = {
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#F781F3',
fillOpacity: 0.35,
map: map,
center: new google.maps.LatLng(city[0],city[1]),
radius: 120701
};
var innerCircleOptions = {
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#F4FA58',
fillOpacity: 0.35,
map: map,
center: new google.maps.LatLng(city[0],city[1]),
radius: 241402
};
cityOuterCircle = new google.maps.Circle(outerCircleOptions);
cityInnerCircle = new google.maps.Circle(innerCircleOptions);
}
}
function initialize() {
var mapOptions = {
zoom: 2,
center: new google.maps.LatLng(37.09024, -95.712891),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
addMarkers();
addCircle();
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
答案 0 :(得分:0)
它本身并不是一个错误,代码按预期运行,浏览器只是警告你需要花费大量时间并且考虑到你要求客户端渲染120个标记和240个圆圈我会说这是可以预料的。您将不得不考虑优化或重新设计您是ui为了 为了规避这个。
最简单的Google地图优化始终是实施标记聚类器,可用示例here。
或者,您可能希望重新设计功能并向标记添加过滤器?是否有必要一次显示所有点?