I have a google map and I need to draw links between different locations on the map. I am using google maps polyline to draw links between different points. Following is the code:
// code to draw map
var map;
var mapProp = {
// center : new google.maps.LatLng(51.4848, -0.20325),
zoom : 8,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), mapProp);
// data to show the links between locations, first part of lat & long denotes from location and second part is to location for a link.
var links_data = [
{"path":[{"lat":53.408123,"lng":-2.985655},{"lat":53.416366,"lng":-2.985655}]},
{"path":[{"lat":53.416366,"lng":-2.985655},{"lat":53.408123,"lng":-3.038971}]},
{"path":[{"lat":53.409477,"lng":-2.982685},{"lat":53.390648,"lng":-3.014405}]},
{"path":[{"lat":53.390648,"lng":-3.014405},{"lat":53.409477,"lng":-2.982685}]},
{"path":[{"lat":53.407086,"lng":-2.989244},{"lat":53.390648,"lng":-3.014405}]},
{"path":[{"lat":53.390648,"lng":-3.014405},{"lat":53.407086,"lng":-2.989244}]},
{"path":[{"lat":53.409477,"lng":-2.982685},{"lat":53.407086,"lng":-2.989244}]},
{"path":[{"lat":53.409477,"lng":-2.982685},{"lat":53.409477,"lng":-2.982685}]},
{"path":[{"lat":53.389557,"lng":-2.989244},{"lat":53.388615,"lng":-3.015866}]},
{"path":[{"lat":53.388615,"lng":-3.015866},{"lat":53.409477,"lng":-2.982685}]},
{"path":[{"lat":53.388615,"lng":-3.015866},{"lat":53.407086,"lng":-2.989244}]},
{"path":[{"lat":53.409477,"lng":-2.982685},{"lat":53.389557,"lng":-3.014986}]},
{"path":[{"lat":53.388615,"lng":-3.015866},{"lat":53.390648,"lng":-3.014405}]},
{"path":[{"lat":53.389557,"lng":-3.014405},{"lat":53.389557,"lng":-3.022483}]},
{"path":[{"lat":53.408123,"lng":-3.038971},{"lat":53.410152,"lng":-3.022483}]},
{"path":[{"lat":53.416366,"lng":-2.985655},{"lat":53.410152,"lng":-3.022483}]},
{"path":[{"lat":53.410152,"lng":-3.022483},{"lat":53.408123,"lng":-3.038971}]},
{"path":[{"lat":53.410152,"lng":-3.022483},{"lat":53.416366,"lng":-2.985655}]}
];
// draw links
for(var i = 0 ; i < links_data.length; i++)
{
var latLng = links_data[i].path;
// polylines lat long array
var polypoints = [];
for ( var j = 0; j < latLng .length; j++) {
polypoints[j] = new google.maps.LatLng(
parseFloat(latLng [j].lat),
parseFloat(latLng [j].lng));
}
var link = new google.maps.Polyline({
path : polypoints,
geodesic : true,
strokeColor : col,
strokeOpacity : 0.5,
strokeWeight : 3,
title : "test"
});
link.setMap(map);
}
I am facing a issue the maps sometimes shows irrelevant lines (few of them marked in black ellipse) as shown in the image below:
any idea whats the issue about?. I am using goggle api from the following url https://maps.googleapis.com/maps/api/js?v=3.exp;
See Question&Answers more detail:os