我看不出地图上的折线图。我使用setPath并提取变量: points中的位置点。我要在地图上显示多条线。如有任何建议,将不胜感激:)谢谢!
var markers = [];
var iterator = 0;
var map;
var mapCenter=new google.maps.LatLng(24.804188,54.862747);
var points = [
['Airport', 24.433241, 54.651096, 12, '#airport'],
['Marine Mall', 24.475968, 54.320953, 11, '#marinemall'],
['Farrari World', 24.481739, 54.606426, 10, '#'],
['Atlantis', 25.1299, 55.117924, 10, '#'],
['Dubai Mall', 25.197126, 55.279092, 10, '#'],
['Burj Khalifa', 25.197097, 55.274144, 10, '#'],
['Burj Al Arab', 25.141167, 55.185472, 10, '#'],
['Water Park', 25.134358, 55.120317, 10, '#']
];
function initialize() {
var styles = [
{
featureType: 'all',
elementType: 'label',
stylers: [
{ visibility:"off" }
]
}
];
var mapOptions = {
center: mapCenter,
zoom:10,
mapTypeId:google.maps.MapTypeId.HYBRID
};
map=new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
map.setOptions({styles:styles});
setPath(map, points);
}
function setPath(map, locations){
for (var i = 0; i < locations.length; i++) {
var place = locations[i];
var myLatLng = new google.maps.LatLng(place[1], place[2]);
var line = new google.maps.Polyline({
map: map,
geodesic: true,
path:myLatLng,
strokeColor:"#ED5552",
strokeOpacity:1,
strokeWeight:2
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);发布于 2014-03-04 10:47:11
在下面的代码部分中
function setPath(map, locations)
{
for (var i = 0; i < locations.length; i++)
{
var place = locations[i];
var myLatLng = new google.maps.LatLng(place[1], place[2]);
var line = new google.maps.Polyline({
map: map,
geodesic: true,
path:myLatLng,
strokeColor:"#ED5552",
strokeOpacity:1,
strokeWeight:2
});
}
}在每个循环中创建myLatLng变量,使其在外部循环中定义数组,并从point/Location array中推送每个latlng,并创建var line = new google.maps.Polyline({.... (这是外部循环)。
下面是使用更改的代码的演示
https://stackoverflow.com/questions/22168871
复制相似问题