-
Notifications
You must be signed in to change notification settings - Fork 1
/
google_map_path.html
69 lines (55 loc) · 2.07 KB
/
google_map_path.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html>
<head>
<title>Draw a polyline given many coordinates</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var coordinates = [[17.251586899999996, 78.41629870000001], [17.3615965, 78.42767459999999], [17.367224399999998, 78.4307278], [17.4117706, 78.4622003], [17.415007199999998, 78.49367420000002], [17.4483438, 78.52897270000001], [17.503054300000002, 78.54079759999999], [17.5449, 78.5718]];
var avglat=0, avglng=0;
for (var i = 0; i < coordinates.length; i++) {
avglat+=coordinates[i][0];
avglng+=coordinates[i][1];
}
avglat/=coordinates.length;
avglng/=coordinates.length;
var homeLatlng = new google.maps.LatLng(avglat, avglng);
var myOptions = {
zoom: 15,
center: homeLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var arrCoords = [];
for (var i = 0; i < coordinates.length; i++) {
arrCoords.push(new google.maps.LatLng(coordinates[i][0],coordinates[i][1]))
}
for (var i = 0; i < coordinates.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(coordinates[i][0], coordinates[i][1]),
map: map,
});
}
// draw the route on the map
var route = new google.maps.Polyline({
path: arrCoords,
strokeColor: "#00FF00",
strokeOpacity: 1.0,
strokeWeight: 4,
geodesic: false,
map: map
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>